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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 PID Controller Tuning에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by