欢迎光临散文网 会员登陆 & 注册

MATLAB微分方程中出现警告: Support of character vectors and strings will b

2023-02-09 11:33 作者:珍宝杂货铺  | 我要投稿


MATLAB微分方程中出现

警告: Support of character vectors and strings will be removed in a future release. Use sym objects to define differential equations instead. 

原因是现在微分方程(dsolve函数)标准的求解方法是用diff和申明函数相结合,新的matlab版本对于字符串转符号变量都不支持了,只是警告,计算结果是没有问题的。

标准求解:

syms y(t)

dsolve(diff(y,t) == y)

S = dsolve(eqn)

S = dsolve(eqn,cond)

S = dsolve(eqn,cond,Name,Value)

[y1,...,yN] = dsolve(___)

eqn代表一个符号方程。

cond代表使用初始条件或边界条件条件。

例子:

例子

出现警报的例子:

 >>y = dsolve('D2y+4*Dy+29*y','y(0)=0,Dy(0)=15','x')

y =

 

3*sin(5*x)*exp(-2*x)


准的求解方法的例子:

syms y(x)  % 先申明y是关于x的函数

>> eqn = diff(y,2)+4*diff(y)+29*y==0;

>> Dy = diff(y);

>> cond = [y(0)==0,Dy(0)==15];

>> ySol(x) = dsolve(eqn,cond)

 

ySol(x) =

 

3*sin(5*x)*exp(-2*x)


总结:对于当前快速计算而言,可以忽视警报。对于完美运行程序者,请使用标准解法。



MATLAB微分方程中出现警告: Support of character vectors and strings will b的评论 (共 条)

分享到微博请遵守国家法律