ODE45 to solve a 2nd order differential equation with a parameter that changes in time

7 次查看(过去 30 天)
Hello! I have been working all day to solve a relatively simple second order differential equation with a parameter that has a different value for each second, but I can't get it to work. I have looked at all questions regarding this subject, but none seem to work. How do I write down my equation or ODE45 function to incorporate the time-dependence of the heave?
function [dxdt] = pitchODE(t,x,omega_5,heave,GM0,M)
dxdt_1 = x(2);
dxdt_2 = -2*0.03*omega_5*x(2)-omega_5^2*(1-(heave(t)/(2*GM0)))*x(1)+M;
dxdt = [dxdt_1; dxdt_2];
end
My heave parameter is the height of my offshore structure at each second in time.
%Defining some parameters
time = 1:1:200; %sec
M = 1; %N/m
GM0 = 2; %m
omega_5 = 0.211; %0.22 Pitch natural freq in rad/s
heave = [ ]; %a parameter with 200 values, corresponding with the 200 seconds in time
initial_x = 0;
initial_dxdt = 0;
initial_cond = [initial_x initial_dxdt]
[t,x] = ode45(@(t,x) pitchODE(t,x,omega_5,heave,GM0,M) ,time,initial_cond)
plot(t, x(:,1))

采纳的回答

Star Strider
Star Strider 2020-11-26
Interp[olate to find the appropriate values of ‘heave’ (that I call ‘heavet’ in ‘pitchODE’ ‘dxdt2’):
function [dxdt] = pitchODE(t,x,omega_5,heave,GM0,M,time)
heavet = interp1(time, heave, t);
dxdt_1 = x(2);
dxdt_2 = -2*0.03*omega_5*x(2)-omega_5^2*(1-(heavet/(2*GM0)))*x(1)+M;
dxdt = [dxdt_1; dxdt_2];
end
%Defining some parameters
time = 1:1:200; %sec
M = 1; %N/m
GM0 = 2; %m
omega_5 = 0.211; %0.22 Pitch natural freq in rad/s
heave = [ ]; %a parameter with 200 values, corresponding with the 200 seconds in time
heave = rand(1,200);
initial_x = 0;
initial_dxdt = 0;
initial_cond = [initial_x initial_dxdt]
[t,x] = ode45(@(t,x) pitchODE(t,x,omega_5,heave,GM0,M,time) ,time,initial_cond);
plot(t, x(:,1))
I used a random vector for ‘heave’ to test my code.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by