Try this:
syms x1 x2 t
x1_dot = (6*atan((53*x1)/9))/(25*pi) - 40*x1 + (6*atan((179*x2)/18))/(25*pi);
x2_dot = (6*atan((53*x1)/9))/(25*pi) - 40*x1 + (6*atan((179*x1)/18))/(25*pi);
x_dot_num = matlabFunction([x1_dot; x2_dot], 'Vars', {t, [x1 x2]});
x1_0 = 4;
x2_0 = 5;
ic = [x1_0 x2_0];
tspan = [0 3];
[t,x_dot_sol] = ode45(@(t,in2)x_dot_num(t,in2.'),tspan,[x1_0 x2_0]);
figure
plot(t, x_dot_sol)
grid
The ‘[x1 x2]’ vectoir in the 'Vars' argument creates them as a parameter set, however it defines them as a row vector. Since the MATLAB ODE solvers want them as a column vector, this call to ‘x_dot_num’:
@(t,in2)x_dot_num(t,in2.')
(note the transpose of ‘in2’) in the ode45 call corrects for that.
This code runs without error. (I left the commented-out lines in so you can understand the changes.)
Best Answer