How to solve two coupled differential equations using ode45.
60 views (last 30 days)
Show older comments
Musanna Galib
on 18 Oct 2020
Commented: haohaoxuexi1
on 12 Aug 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 Comments
Accepted Answer
Alan Stevens
on 19 Oct 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 Comments
Alan Stevens
on 19 Jan 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
on 19 Jan 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.
More Answers (1)
Alan Stevens
on 20 Jan 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 Comment
haohaoxuexi1
on 12 Aug 2022
Is there any way to solve it analytically? Or any sample code can be shared
See Also
Categories
Find more on Eigenvalue Problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!