how do i get the solution from ODE45?
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 30 de En. de 2022
0 votos
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.
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!