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

1 visualizzazione (ultimi 30 giorni)
% 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

Risposte (1)

Ameer Hamza
Ameer Hamza il 12 Giu 2020
Modificato: Ameer Hamza il 12 Giu 2020
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.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by