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

1 次查看（过去 30 天）
Keith Grey2020-6-11

% 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 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);
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.

### 类别

Find more on Ordinary Differential Equations in Help Center and File Exchange

R2017b

### Community Treasure Hunt

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

Start Hunting!

Translated by