How to solve two coupled differential equations using ode45.

조회 수: 59 (최근 30일)
Musanna Galib
Musanna Galib 2020년 10월 18일
댓글: haohaoxuexi1 2022년 8월 12일
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.

채택된 답변

Alan Stevens
Alan Stevens 2020년 10월 19일
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
Alan Stevens
Alan Stevens 2022년 1월 19일
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
haohaoxuexi1 2022년 1월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alan Stevens
Alan Stevens 2022년 1월 20일
"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
haohaoxuexi1
haohaoxuexi1 2022년 8월 12일
Is there any way to solve it analytically? Or any sample code can be shared

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by