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

1 回表示 (過去 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.
  2 件のコメント
Tijmen
Tijmen 2020 年 11 月 26 日
Thank you very much!! Works like a charm
Star Strider
Star Strider 2020 年 11 月 26 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePID Controller Tuning についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by