Not enough input arguments error in ode23?

12 次查看(过去 30 天)
Ekran Alıntısı.PNG
I try to use ode23 solver to my 3rd order ODE function. The function is given above.The range of t is from 1 to 4 .
The syntax that i must use is [t, y]= solver(@odefun, tspan, y0)
I also have initial conditions, but i confused where should i put them in the syntax.
Initial conditions are y(1)=0, y'(1)=1 and y''(1)=3.
function yprime = ydotfunc(t,y)
yprime(1)=y(2);
yprime(2)=5*(t^3)*exp(t)+9*(t^3)-3*t*y(2)+4*y(1);
yprime(3)=5*(t^3)*exp(t)+9*(t^3)+(t^2)*y(3)-3*t*y(2)+4*y(1);
end
clc
close all hidden
format long
tspan=[1 4];
IC=[1;1;-1];
[t,u]=ode23(@ydotfunc,tspan,IC);
y_true=@(t) -(t.^2)+t.*cos(log(t))+t.*sin(log(t))+(t.^3).*log(t);
y1=y_true(t);
figure(1)
plot(t,y(:,1),'ro',t,y1,'b-')
title('Plot of y1')
xlabel('t')
ylabel('y1')
legend('Numerical Solution','Exact Solution')

回答(1 个)

Star Strider
Star Strider 2019-5-23
Most of what you are doing appears to be correct (I removed the clc and close calls):
tspan=[1 4];
IC=[1;1;-1];
[t,y]=ode23(@ydotfunc,tspan,IC);
y_true=@(t) -(t.^2)+t.*cos(log(t))+t.*sin(log(t))+(t.^3).*log(t);
y1=y_true(t);
figure(1)
plot(t,y(:,1),'ro',t,y1,'b-')
title('Plot of y1')
xlabel('t')
ylabel('y1')
legend('Numerical Solution','Exact Solution')
The Symbolic Math Toolbox odeToVectorField function disagrees with your coding of your differential equation, and gives a result closer to the exact solution.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by