matlab解微分方程画图?function mat1()syms yt=0:0.1:1y=dsolve('Dy=1-2*y+t','t')[y]endcommand window:t =0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000y =t/2 + C3/(4*exp(2*t)) + 1/4y =t/2 + C3/(4*exp(2*t)) + 1/4>> plot(t

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 01:02:36
matlab解微分方程画图?function mat1()syms yt=0:0.1:1y=dsolve('Dy=1-2*y+t','t')[y]endcommand window:t =0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000y =t/2 + C3/(4*exp(2*t)) + 1/4y =t/2 + C3/(4*exp(2*t)) + 1/4>> plot(t

matlab解微分方程画图?function mat1()syms yt=0:0.1:1y=dsolve('Dy=1-2*y+t','t')[y]endcommand window:t =0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000y =t/2 + C3/(4*exp(2*t)) + 1/4y =t/2 + C3/(4*exp(2*t)) + 1/4>> plot(t
matlab解微分方程画图?
function mat1()
syms y
t=0:0.1:1
y=dsolve('Dy=1-2*y+t','t')
[y]
end
command window:
t =
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
y =
t/2 + C3/(4*exp(2*t)) + 1/4
y =
t/2 + C3/(4*exp(2*t)) + 1/4
>> plot(t,y)
Undefined function or variable 'y'.

matlab解微分方程画图?function mat1()syms yt=0:0.1:1y=dsolve('Dy=1-2*y+t','t')[y]endcommand window:t =0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000y =t/2 + C3/(4*exp(2*t)) + 1/4y =t/2 + C3/(4*exp(2*t)) + 1/4>> plot(t

存在的问题:

1、解微分方程的代码写在一个函数里,函数有自己独立工作区,运行函数后,变量的值不会自动保存在命令窗口里,所以会提示y未定义(你应该在之前定义过t,否则应该提示t未定义).

2、微分方程没提供初始条件,因而求解得到的表达式中含有自由系数C3.

3、解微分方程得到的y是t的表达式,需要将t的实际取值代入才可以得到绘图所需数据.

 

参考代码(假定初值为0):

syms  y
t=0:0.1:1;
y=dsolve('Dy=1-2*y+t','y(0)=0')
y=subs(y);
plot(t,y)