Error Message "Input argument 't' might be unused" OR "Not enough Input Arguments"

function dvdt = deqn(t,v,M,G,K)
dvdt = [v(1); G-((K/M)*(v^2))];
M = 5;
K = 0.125;
G = 32;
tspan = (0:5);
v0 = [0 0];
[t,v] = ode45(@(t,v) odefun(t,v,M,G,K), tspan, v0);
plot(t,v)
Can anyone help me fix this? I need 't' to graph a velocity versus time function using this ODE.

Réponses (1)

Try this:
odefun = @(t,v,M,G,K) [v(1); G-((K/M)*(v(2)^2))]; % Guessing That The ‘v^2’ Term Should Be ‘v(2)^2’
M = 5;
K = 0.125;
G = 32;
tspan = (0:5);
v0 = [0 0];
[t,v] = ode45(@(t,v) odefun(t,v,M,G,K), tspan, v0);
plot(t,v)
That worked when I ran it (R2020a).

2 commentaires

It worked, thank you so much!
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Connectez-vous pour commenter.

Catégories

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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by