solving coupled differential equations

조회 수: 18 (최근 30일)
MAMTA SINGH
MAMTA SINGH 2019년 6월 1일
답변: Bjorn Gustavsson 2019년 6월 1일
I have three equations, two are first order and one is second order. Kindly suggest the code to solve it. I have attached my equations in attachment.
Thanks

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 6월 1일
For symbolic solutions look at the help for dsolve, for numerical soutions convert the 2nd order ode to 2 coupled first-order odes, then put all 4 first-order ODEs into one function and one of the odeNN (ode45, ode23, etc) with that function, the time-spand and your initial condition. Something like this would be the ODE-function:
function dydt = your_ode(t,y)
w_m = 21; % and so on for your other constants - you could also have them as additional inputs
w1 = y(1);
w2 = y(2);
f = y(3);
dfdt = y(4);
dw1dt = (w_m - y(3))*exp(f-12t);
dw2dt = (w1 - w2*sin(12*t));
d2fdt2 = f+12*w1-w2; % change to your actual ODEs here...
dydt = [dw1dt;dw2dt;dfdt;d2fdt2];
end
Then call, for example, ode45:
w1_0 = 123;
w2_0 = 231;
f_0 = exp(pi);
dfdt_0 = sqrt(2);
y0 = [w1_0;w1_0;f_0;dfdf_0];
t = [0,37];
[T,w1w2fdfdt] = ode45(@(t,y) your_ode(t,y),t,y0);
HTH

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by