Not enough input arguments error in ode23?

12 visualizaciones (últimos 30 días)
Burhan Elaldi
Burhan Elaldi el 23 de Mayo de 2019
Respondida: Star Strider el 23 de Mayo de 2019
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')

Respuestas (1)

Star Strider
Star Strider el 23 de Mayo de 2019
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.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by