ODE45 to solve a 2nd order differential equation with a parameter that changes in time
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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))
0 commentaires
Réponse acceptée
Star Strider
le 26 Nov 2020
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 commentaires
Star Strider
le 26 Nov 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur PID Controller Tuning dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!