Trouble using the ode45 input
Mostra commenti meno recenti

1 Commento
Stephen23
il 6 Nov 2023
You need to parameterize the function call:
See Star Strider's answer for an example of this.
Risposte (2)
Hi @Isabella
From the ODE, the analytical solution is a sine wave. If the parameters
are some fixed values, then you can place them inside the function f.
[t, y] = ode45(@f, [0 15], [-0.9 0]);
plot(t, y), grid on, xlabel('t'), legend('y(t)', 'v(t)')
function dy = f(t, y)
dy = zeros(2, 1);
m = 4;
k = 21;
omega = sqrt(k/m);
dy(1) = y(2);
dy(2) = -(omega^2)*y(1);
end
Star Strider
il 6 Nov 2023
0 voti
The call to ‘f’ in the ode45 call (and the correct ode45 call) should be:
[t,Y] = ode45(@(t,y)f(t,y,omega0), [0, 15], [y0,v0]);
My MATLAB release (R2023b) can still not run images of code, only actual code. (Perhaps that will be an upgrade in a future release?!)
.
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
