In the line where I define "phi", I get the error.
% y(1) = theta
% y(2) = theta'
% y(3) = spi
% y(4) = spi'
function dydt = DifLign(t,y) L_4 = 1;% constants
m = 2;M = 3;M_K = 4;L_1 = 1;L_2 = 1;L_3 = 1;g = 9.8;theta_i = 48; % relations between phi and theta
phi = -asin(L_1*((-cos(theta_i)+cos(y(1)))/L_4));f_theta = cos(y(1)-phi)/cos(phi);df_theta = -sin(y(1)-phi)/cos(phi) + (L_1*sin(y(1))^2)/(L_4*cos(y(1))^3); % Equations
A_11 = m*(L_1^2)*(f_theta^2) + M*(L_2^2) + (1/3)*M_K*((L_1^2)-L_1*L_2+(L_2^2));A_12 = -M*L_2*L_3*cos(y(1)-y(3));A_21 = -L_2*cos(y(1)-y(3));A_22 = L_3 a_1 = -m*(L_1^2)*(f_theta^2)*(df_theta)*(y(2))^2 + M*L_2*L_3*sin(y(1)-y(3))*(y(4))^2 + (M*L_2-M_K*((L_1-L_2)/2))*sin(y(1))*g;a_2 = -L_2*sin(y(1)-y(3))*(y(2))^2 - g*sin(y(3)); % First order equations
% theta_1 = theta'
% theta_2 = theta''
% spi_1 = spi'
% spi_2 = spi''
theta_1 = y(2);theta_2 = A_22/(A_11*A_22-A_12*A_21)*a_1 - A_12/(A_11*A_22-A_12*A_21)*a_2;spi_1 = y(3);spi_2 = A_21/(A_11*A_22-A_12*A_21)*a_1 + A_11/(A_11*A_22-A_12*A_21)*a_2; dydt = [theta_1; theta_2; spi_1; spi_2];
Best Answer