I try to solve an equation with the command ode45 b ut I have an error, this is my code:
tspan = [0 5];
y0 = 100;
Q = 30, b = 0.2;
[t,y,x] = ode45(@(tspan,y,x) Q-b*x*y, t, y0);
plot (t,y,x,'-o')
and the error:
Q =
30
Not enough input arguments.
Error in rungrkutta_y>@(tspan,y,x)Q-b*x*y (line 4)
[t,y,x] = ode45(@(tspan,y,x) Q-b*x*y, t, y0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in rungrkutta_y (line 4)
[t,y,x] = ode45(@(tspan,y,x) Q-b*x*y, t, y0);
how can I solve it?

 Réponse acceptée

Star Strider
Star Strider le 1 Mar 2021
I have no idea what you want to do, or what ‘x’ and ‘y’ are.
This will get you closer to an actual result:
tspan = [0 5];
y0 = [100; 0];
Q = 30;
b = 0.2;
[t,y] = ode45(@(t,y) [y(1); Q-b*y(1)*y(2)], tspan, y0);
figure
plot (t,y,'-o')
.

4 commentaires

I want to represent the solution of this system with the command ode45:
dx/dt = P-axy
dy/dt = Q-bxy
but I don´t know how to do it exactly
Try this:
tspan = [0 5];
y0 = [100; 0]; % Supply The Correct Initial Value For ‘y’
Q = 30;
b = 0.2;
a = 0.1; % Not Supplied
P = 10; % Not Supplied
[t,y] = ode45(@(t,y) [P-a*y(1)*y(2); Q-b*y(1)*y(2)], tspan, y0); % x=y(1), y=y(2)
figure
plot (t,y,'-o')
grid
legend('x(t)', 'y(t)')
I created values for the missing scalars to test the code. You will need to supply the correct values.
I think that it will work, thank you!
Star Strider
Star Strider le 1 Mar 2021
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Stephan
Stephan le 1 Mar 2021
tspan = [0 5];
y0 = 100;
Q = 30;
b = 0.2;
[t,y] = ode45(@(t,y)Q-b*t*y, tspan, y0);
plot (t,y,'-o')

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by