MATLAB: Can’t understand why does it say “The expression to the left of the equals sign is not a valid target for an assignment.”

ode45symbolicSymbolic Math Toolbox

1- function dydt = lagrang(~, y)
2- syms m1 m2 m3 l1 l2 l3 g
3- dydt = zeros(6,5,4,3,2,1);
4- m1=1; m2=1; m3=1; l1=1; l2=1; l3=1; g=9.81;
5- dydt(1)=y(2);
6- dydt(3)=y(4);
7- dydt(5)=y(6);
8- dydt(1)*(l1^2*(m1+m2+m3))+dydt(3)((m2+m3)*l1*l2*cos(y(1)-y(3)))+dydt(5)*(m3*l1*l3*cos(y(1)-y(5)))=-(m2+m3)*l1*l2*y(4)^2*sin(y(1)-y(3))-m3*l1*l3*y(6)^2*sin(y(1)-y(5))-(m1+m2+m3)*g*l1*cos(y(1));
9- dydt(1)*((m2+m3)*l1*l2*cos((y(1)-y(3))))+dydt(3)*(l2^2*(m2+m3))+dydt(5)*(m3*l2*l3*cos(y(3)-y(5)))=(m2+m3)*l1*l2*y(2)^2*sin(y(1)-y(3))-m3*l2*l3*y(6)^2*sin(y(3)-y(5))-(m2+m3)*g*l2*cos(y(3));
10- dydt(1)*(m3*l1*l3*cos(y(1)-y(5)))+dydt(2)*m3*l2*l3*cos(y(3)-y(5))+dydt(l3^2*m3)=m3*l1*l3*y(2)^2*sin(y(1)-y(5))+m3*l2*l3*y(4)^2*sin(y(3)-y(5))-m3*g**l3*cos(y(5))
%other part
dydt = [0; pi/2; 0; pi/2; 0; pi/2];
[t1,y1] = ode45(@lagrang, [0 20], dydt);
plot(t1,y1(:,2));
When I run this, I get a problem. Sorry if this is a simple problem to solve, since I am new to this program, it's been one week for me since i started.
Error: File: lagrang.m Line: 8 Column: 98
The expression to the left of the equals sign is not a valid target for an assignment.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in lagrange_ans (line 2)
[t1,y1] = ode45(@lagrang, [0 20], dydt);
The equations' itself:
Adsız4.png Adsız5.png
Where do i go wrong?

Best Answer

syms theta1(t) theta2(t) theta3(t)
m1=1; m2=1; m3=1; l1=1; l2=1;
l3=1; g=9.81; tau1=1; tau2=1; tau3=1;
e1= diff(theta1,2)*(l1^2*(m1+m2+m3)+l1)+...
diff(theta1,2)*((m2+m3)*(l1*l2*cos(theta1-theta2)))+...
diff(theta3,2)*(m3*l1*l3*cos(theta1-theta3))==...
-(m2+m3)*(l1*l2*diff(theta2)^2*sin(theta1-theta2))-...
m3*l1*l3*diff(theta3)^2*sin(theta1-theta3)-...
(m1+m2+m3)*g*l1*cos(theta1)+tau1-tau2;
e2= diff(theta1,2)*((m2+m3)*l1*l2*cos(theta1-theta2))+...
diff(theta2,2)*(l2^2*(m2+m3)+l2)+...
diff(theta3,2)*(m3*l2*l3*cos(theta2-theta3))==...
(m2+m3)*l1*l2*diff(theta1)^2*sin(theta1-theta2)-...
m3*l2*l3*diff(theta3)^2*sin(theta2-theta3)-...
(m2+m3)*g*l2*cos(theta2)+tau2-tau3;
e3= diff(theta1,2)*(m3*l1*l3*cos(theta1-theta3))+...
diff(theta2,2)*(m3*l2*l3*cos(theta2-theta3))+...
diff(theta3,2)*(l3^2*m3+l3)==...
m3*l1*l3*diff(theta1)^2*sin(theta1-theta3)+...
m3*l2*l3*diff(theta2)^2*sin(theta2-theta3)-...
m3*g*l3*cos(theta3)+tau3;
vars = [theta1(t); theta2(t); theta3(t)]
V = odeToVectorField([e1,e2,e3])
M = matlabFunction(V,'vars', {'t','Y'})
interval = [0 20]; %time interval
y0 = [0; pi/2; 0; pi/2; 0; pi/2]; %initial conditions
ySol = ode45(M,interval,y0);
tValues = linspace(interval(1),interval(2),1000);
for i = 1:6 % denotes the number of solutions
yValues = deval(ySol,tValues,i); % i denotes the solution number
plot(tValues,yValues)
hold on
end
Plot of 6 solutions:
Screen Shot 2019-01-02 at 8.08.16 PM.png