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 views (last 30 days)
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;
^^^^

Answers (1)

Star Strider
Star Strider on 8 Oct 2025 at 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.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!