clc; clear all; close all
tspan = [0 5];
y0 = 0;
[t,y] = ode113(@(t,y) 2*t, tspan, y0);
disp([t,y]);
plot(t,y)
How do I print the solution of this ode? y'=2*t , I want to print the result, in this case y=t^2, on the screen.

 채택된 답변

Sam Chak
Sam Chak 2022년 4월 14일
Use the text() function:
tspan = [0 5];
y0 = 0;
[t, y] = ode45(@(t,y) 2*t, tspan, y0);
% disp([t, y]);
plot(t, y)
text(3, 8,'\leftarrow y = t^2')

댓글 수: 4

For more options, you can refer to this documentation:
If you want to display the solution on the Command Window screen, then this one should do:
Sol = 'y(t) = t^2';
disp(Sol)
I see that you wrote the solution in to a string, is there a way in which the output from the ode113 function prints the result ? the y(t) =t^2 ?
Sam Chak
Sam Chak 2022년 4월 14일
편집: Sam Chak 2022년 4월 14일
The ode113() function is a numerical approach. If you want to get the analytical solution by symbolically solving the ODE, then you have to use the dsolve() function (Symbolic Math Toolbox required).
syms y(t)
eqn = diff(y,t) == 2*t;
cond = y(0) == 0;
ySol(t) = dsolve(eqn, cond)
ySol(t) =
t^2
Corrected.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2020a

질문:

2022년 4월 14일

편집:

2022년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by