Trouble using the ode45 input
이전 댓글 표시

댓글 수: 1
Stephen23
2023년 11월 6일
You need to parameterize the function call:
See Star Strider's answer for an example of this.
답변 (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
2023년 11월 6일
0 개 추천
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?!)
.
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
