Matlab Simulink - How to simulation this math?

1 回表示 (過去 30 日間)
Minh Danl
Minh Danl 2020 年 11 月 6 日
編集済み: Ameer Hamza 2020 年 11 月 6 日

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 6 日
編集済み: Ameer Hamza 2020 年 11 月 6 日
You need to use ode45(): https://www.mathworks.com/help/matlab/ref/ode45.html . Convert your 2nd order ODE into a system of 2 first-order ODEs. The following code assumes F(t)=1.
tspan = [0 10];
IC = [0; 0]; % initial condition
[t, X] = ode45(@odeFun, tspan, IC);
plot(t, X, '-o')
legend({'$x$', '$\dot{x}$'}, 'FontSize', 16, 'Interpreter', 'latex', 'Location', 'best')
function dxdt = odeFun(t, x)
c = 2;
k = 1;
m = 5;
F = 1;
dxdt = zeros(2,1);
dxdt(1) = x(2);
dxdt(2) = (F - c*x(2) - k*x(1))/m;
end

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by