I know line 4 goes wrong,but I don't know how to correct it. If anyone know it,I firmly hope to get your advice.

9 次查看(过去 30 天)
syms t y(t)
eqn=diff(y,t)==t*y;
cond=y(0)==2;
ySol=dsolve(eqn,cond);
disp('微分方程的解:')
微分方程的解:
disp(ySol)
fplot(ySol,[0,2])
title('一阶线性微分方程 dy/dt=t*y的解')
xlabel('时间 t')
ylabel('y(t)')
grid on
出错 Rick_ (第 4 行)
cond=y(0)==2;
^^^^

回答(1 个)

Star Strider
Star Strider 2025-10-8,15:54
Your code looks correct to me. You set the initial condition to be 'y(0)==2' and that is what dsolve returned: From the plot, it is also obvious that 'y(t)' begins at 2.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by