How can I solve & this 2nd order differential equation?

1 回表示 (過去 30 日間)
Keith Grey
Keith Grey 2020 年 6 月 11 日
編集済み: Ameer Hamza 2020 年 6 月 12 日
% x = x''
% y = x'
% z = x
% Conditions
f = 50:1:200; % Frequency span (Hz)
for f = 50:1:200
Equation = 50x - 100y - 25z == -1(f * 2 * pi);
plot(f, Equation)
hold on
end

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 6 月 12 日
編集済み: Ameer Hamza 2020 年 6 月 12 日
This shows how to solve this ODE for all values of 'f', and plot the solution as a surf plot
f = 50:1:200;
t = linspace(0, 10, 1000); % solve the equation for t in [0, 10]
ic = [0; 0]; % initial condition
Y = zeros(numel(f), numel(t));
for i = 1:numel(f)
[~, y] = ode45(@(t, x) odeFun(t, x, f(i)), t, ic);
Y(i, :) = y(:, 1);
end
surf(t, f, Y);
shading interp
xlabel('t');
ylabel('f');
zlabel('x');
function dxdt = odeFun(t, x, f)
dxdt = zeros(2, 1);
dxdt(1) = x(2);
dxdt(2) = 1/50*(100*x(2) + 25*x(1) - 1*2*pi*f);
end
Also see this example: https://www.mathworks.com/help/matlab/ref/ode45.html#bu3uj8b. It shows how to convert the 2nd-order ODE into a system of 2 first-order ODEs.

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by