dsolve 生成​​不一致的输出

dsolve generating inconsistent outputs

我已经玩了一段时间了,谁能解释一下为什么我从 Code1 和 Code2 得到不同的答案? 'dsolve()' 的实际脚本是什么使这两个代码的输出不同?如果我只是使用不同的语法(即 ',;".'),输出是否相同?

%Code1:

syms Qua t Area height

rate_in = 3*Qua*(sin(t))^2; 
delta_Vol = dsolve('DAreaY = rate_in - Qua');
delta_Height= dsolve('Dheight = ((rate_in - Qua)/Area)', 'height(0) = 0');
 subfnc1 = subs(rate_in, {Qua}, {450});
fnc1 = subs(delta_Height, {'rate_in'}, {subfnc1});
fnc1 = subs(fnc1, {Area, Qua}, {1250,450});
fnc_main = matlabFunction(fnc1);
fnc_main(0:10)';

%Code2:

syms Qua t Area height

rate_in = 3*Qua*(sin(t))^2; 
delta_Vol = dsolve('DAreaY = 3*Qua*(sin(t))^2 - Qua');
delta_Height= dsolve('Dheight = ((3*Qua*(sin(t))^2 - Qua)/Area)', 'height(0) = 0');
fnc1 = subs(delta_Height, {Area, Qua}, {1250,450});
fnc_main = matlabFunction(fnc1);
fnc_main(0:10)';

我不明白的 dsolved 函数是什么?

问题可能是您将字符串而不是符号表达式传递给 dsolve。这意味着在第一种情况下 rate_i 可能被解释为常数,而不是 t.

的函数

这可能是您尝试做的事情:将 Dheight 也定义为 sym,并告诉 dsolve 使用 syms 做什么:

%Code1:

clear Qua t Area height Dheight
syms Qua t Area height(t) Dheight

Dheight = diff(height);
rate_in = 3*Qua*(sin(t))^2; 
delta_Height= dsolve(Dheight == ((rate_in - Qua)/Area), height(0) == 0);
subfnc1 = subs(rate_in, {Qua}, {450});
fnc1 = subs(delta_Height, {'rate_in'}, {subfnc1});
fnc1 = subs(fnc1, {Area, Qua}, {1250,450});
fnc_main = matlabFunction(fnc1)

%Code2:

clear Qua t Area height Dheight
syms Qua t Area height(t) Dheight

Dheight = diff(height);
rate_in = 3*Qua*(sin(t))^2; 
delta_Height= dsolve(Dheight == ((3*Qua*(sin(t))^2 - Qua)/Area), height(0) == 0);
fnc1 = subs(delta_Height, {Area, Qua}, {1250,450});
fnc_main = matlabFunction(fnc1)

对您的版本的更改:

  • 我删除了 delta_Vol,因为它未被使用并且包含对 (D)AreaY
  • 的不明确引用
  • 我在 dsolve 中从字符串更改为符号表达式,同时 = 必须更改为 ==
  • 我将 DHeight 定义为 diff(Height),这意味着 height 必须声明为 height(t)。这也允许我们将初始条件定义为 height(0)==0,否则我们需要将其保留为字符串:'height(0)=0'.

现在两个版本return相同的解决方案:

fnc_main = 

    @(t)t.*(9.0./5.0e1)-sin(t.*2.0).*(2.7e1./1.0e2)

我建议在纸上检查这个解决方案或其象征性的前身,

delta_Height =

(Qua*(2*t - 3*sin(2*t)))/(4*Area)

确实是你的微分方程的解。