how do i get the solution from ODE45?

9 visualizzazioni (ultimi 30 giorni)
my proplem is
y''+25y=-70*sin(5t) while the time interval is [0 pi].
with IC
y(0)=0, y'(0)=7
I have to know the numerical expression for y(t)!!
the exacte solution is y(t)=7*t*sin(5t)
the code I wrote is :
clear; close all; clc;
a = 0;
b = pi;
I1 = 0;
I2 = 7;
F = @(t,y) [y(2);-70*sin(t)-25*y(1)];
[t y] = ode45(F, [a b], [I1;I2]);
plot(t,y(:,1),'b-', t, y(:,2),'r:')
legend('numerical', 'exact','Location', 'best');
my question is, how do I know the expression of the numerical one as same as the exact one but not interpolization.

Risposta accettata

Steven Lord
Steven Lord il 30 Gen 2022
ode45 is a numeric ODE solver. It cannot give you a symbolic solution.
To get a symbolic solution you'd need to use something like dsolve from Symbolic Math Toolbox.

Più risposte (1)

John D'Errico
John D'Errico il 30 Gen 2022
You cannot do so. PERIOD. ODE45 is NOT an analytical solving tool. Would you expect code written for one purpose to perform what you want it to do, even if what you want is not what the code was written to do? ODE45 will (usually accurately) approximate the solution to an ODE, given an initial value and the ODE. It will not provide a symbolic formula for that solution. It CANNOT do that.
Nothing stops you from plotting the ODE45 solution, and on top of that, plottign the known solution. Do they overlay on top of each other? If so, then what is the problem? My guess is, that was what you were asked to do in your homework. So can you plot the function
7*t.*sin(5*t)
on the same set of axes? Note my use of the .* operator there, as it would be important.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by