How do I print the solution equation from an ode solver

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.

 Accepted Answer

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 Comments

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 ?
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.

Sign in to comment.

More Answers (0)

Products

Release

R2020a

Asked:

on 14 Apr 2022

Edited:

on 14 Apr 2022

Community Treasure Hunt

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

Start Hunting!