
How to solve two coupled differential equations using ode45.
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Musanna Galib
il 18 Ott 2020
Commentato: haohaoxuexi1
il 12 Ago 2022
I need help to solve two paired differential equations. After hours of unsuccessful attemps, I am asking for help from you. Any suggestion will be highly appriciated.
The equations are -
m*x''(t) + U*x(t) + γ*x'(t) + kv*V(t) - ζ = 0
V'(t) - kc*x'(t) + τ*V(t) = 0
initial conditions are x(0) = 1, X'(0) = 0, V(0) =0
x and V are the variables. All others are constant.
Thanks in advance.
0 Commenti
Risposta accettata
Alan Stevens
il 19 Ott 2020
The following should help:

% tspan = [0 tend];
% IC = [1 0 0]; % initial conditions
% [t, X] = ode45(@fn, tspan, IC);
% x = X(:,1);
% z = X(:,2);
% V = X(:,3);
%
% function dXdt = fn(t,X)
% x = X(1); z = X(2); V = X(3);
% constants = ... list them with their values
% dXdt = [z;
% -(y*z+U*x+kv*V)/m;
% kc*z-tau*V];
% end
22 Commenti
Alan Stevens
il 19 Gen 2022
I'd be inclined to manipulate the equations to get the following (I'm assuming you know time zero values for y1, y2, dy2/dt and V2):
% Let dy2/dt = v2
% Define the following functions
% fna = @(t,y1,y2,v2,VR) (F0*cos(omega*t)+theta*VR+keq*(y1-y2)-c*v2)/m;
% fnb = @(y1,v2) keq*v2/(knl1+3*knl2*y1^2+keq);
% Set up a rate of change function that will be called by an ODE solver
% function dYdt = rate(t,Y,fna,fnb,fnc)
% y1 = Y(1);
% y2 = Y(2);
% v2 = Y(3);
% VR = Y(4);
% dYdt = [fnb(y1,v2);
% v2;
% fna(t,y1,y2,v2,VR);
% (-R*theta*k1/(k1+kp)*(v2-fnb(y1,v2))-VR)/(R*Cp)];
% end
I can't check these numerically as you haven't supplied vaies for the constants, initial conditions or integration time.
If you intend to try this approach you must very carefully double check that I have manipulated the equations correctly!
haohaoxuexi1
il 19 Gen 2022
dx(1)=(k1*x(3))/(knl_1+3*knl_3*x(1)^2+k1);
dx(2)=x(3);
dx(3)=(-c*x(3)-k1*(x(2)-x(1))+kAmp*cos(w*t)+theta_p*x(4))/m;
dx(4)=(-theta_p*(kspring/(kpiezo+kspring))*(x(3)-((k1*x(3))/(knl_1+3*knl_3*x(1)^2+k1)))*R_s-x(4))/R_s/C_p;
I changed the code to the above way and removed the mass matrix anymore, which follow your suggestions, and it worked with ode45.
I want to know if there is any logical mistake in my previous code? Why is my previous code is not working properly by treating the problem to be a DAE.
Also I noticed you wrote the fna fnb as separate function in your code instead of putting them all in dYdt function? Is there specific reason for you to do it this way? Like it can help calculating faster or it is just your habit?
Thank you for your help anyway.
Più risposte (1)
Alan Stevens
il 20 Gen 2022
"Why is my previous code is not working properly by treating the problem to be a DAE."
I don't know!
"Also I noticed you wrote the fna fnb as separate function in your code instead of putting them all in dYdt function? Is there specific reason for you to do it this way? Like it can help calculating faster or it is just your habit?"
You could put them inside the dYdt function here if you like. I tend to define them outside in case I need to call them separately outside of dYdt.
1 Commento
haohaoxuexi1
il 12 Ago 2022
Is there any way to solve it analytically? Or any sample code can be shared
Vedere anche
Categorie
Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

