Not enough input arguments error in ode23?
이전 댓글 표시

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
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.
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!