how do i get the solution from ODE45?
显示 更早的评论
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.
采纳的回答
更多回答(1 个)
John D'Errico
2022-1-30
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!