Trouble using the ode45 input
Show older comments

1 Comment
Stephen23
on 6 Nov 2023
You need to parameterize the function call:
See Star Strider's answer for an example of this.
Answers (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
on 6 Nov 2023
0 votes
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?!)
.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!