MATLAB: Solving two differential equations using ode45

differential equationsode45

I have two differential equations in the form
-y"-5y'-y=3x"+4x'^2+2x+6t
-y"-2.3y'-2y=2x"+3x'^2+x
I would like to solve these equations using ODE's
the inital conditions are x(0), y(0), x'(0) and y'(0) are known
Thanks in advance

Best Answer

This will help:
Follow the given examples and adapt them to your needs - for example:
syms y(t) x(t) t
ode(1) = -(diff(y,t,2))-5*diff(y,t)-y == 3*diff(x,t,2)+4*diff(x,t)^2+2*x+6*t;
ode(2) = -(diff(y,t,2))-2.3*diff(y,t)-2*y == 2*diff(x,t,2)+3*diff(x,t)^2+x;
pretty(ode)
[V,S] = odeToVectorField(ode)
fun = matlabFunction(V,'Vars',{'t','Y'})
x0 = [2 0 3 0.25];
[t, sol] = ode45(fun,[0 2], x0);
subplot(2,2,1)
plot(t,sol(:,1),'-r')
subplot(2,2,2)
plot(t,sol(:,2),'-b')
subplot(2,2,3)
plot(t,sol(:,1),'-g')
subplot(2,2,4)
plot(t,sol(:,2),'-k')