MATLAB: Solving coupled differential equations

differential equations

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

Best Answer

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