MATLAB: Error using vpasolve-Conversion to ‘sym’ from ‘struct’ is not possible.

equationerrorMATLABvpasolve

Hi all, This is my code.
syms theta1 theta0 theta2 gama M l k_1
eqn=theta1==(k_1*sin(theta0) + k_1*sin(theta1) + k_1^2*sin(k_1*(theta1 - theta2))*cos(gama - theta2) + M*k_1*sin(gama - theta2) + sin(gama - theta2)*sin(k_1*(theta1 - theta2))*sin(theta1) - M*k_1^2*sin(k_1*(theta1 - theta2)) - k_1*cos(theta0)*sin(theta1) + k_1*cos(theta1)*sin(theta0) - k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2)) - M*k_1*sin(theta1) + k_1^2*sin(gama - theta2)*sin(k_1*(theta1 - theta2))*sin(theta0) - sin(gama - theta2)*cos(theta0)*sin(k_1*(theta1 - theta2))*sin(theta1) + sin(gama - theta2)*cos(theta1)*sin(k_1*(theta1 - theta2))*sin(theta0) + M*k_1^2*cos(theta1)*sin(k_1*(theta1 - theta2)) - M*k_1^2*sin(k_1*(theta1 - theta2))*cos(gama - theta2) + k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta0) + k_1*cos(k_1*(theta1 - theta2))*sin(theta0)*cos(gama - theta2) + k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta1) + k_1*cos(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2) - M*k_1*cos(k_1*(theta1 - theta2))*sin(theta1) - k_1^2*cos(theta0)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) - k_1^2*cos(theta1)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) + M*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2)) - M*k_1*sin(gama - theta2)*cos(theta1) - M*k_1*sin(theta1)*cos(gama - theta2) + M*k_1^2*cos(theta1)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) - M*k_1^2*sin(gama - theta2)*sin(k_1*(theta1 - theta2))*sin(theta1) - k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta0)*cos(theta1) - k_1*cos(k_1*(theta1 - theta2))*cos(theta0)*sin(theta1)*cos(gama - theta2) + k_1*cos(k_1*(theta1 - theta2))*cos(theta1)*sin(theta0)*cos(gama - theta2) - k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*sin(theta0)*sin(theta1) + k_1^2*cos(theta0)*cos(theta1)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) - M*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta1) - M*k_1*cos(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2) + k_1^2*sin(k_1*(theta1 - theta2))*sin(theta0)*sin(theta1)*cos(gama - theta2))/(M*l*(2*k_1 + sin(gama - theta2)*cos(theta1)*sin(k_1*(theta1 - theta2)) + sin(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2) + 2*k_1*cos(k_1*(theta1 - theta2))*cos(theta1)*cos(gama - theta2) - 2*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*sin(theta1) + k_1^2*sin(gama - theta2)*cos(theta1)*sin(k_1*(theta1 - theta2)) + k_1^2*sin(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2)))
eqn1=theta2==-(M*k_1^2*sin(k_1*(theta1 - theta2)) - 2*k_1*sin(theta1) - k_1*sin(gama - theta2) - 2*k_1^2*sin(k_1*(theta1 - theta2))*cos(gama - theta2) - M*k_1*sin(gama - theta2) - sin(gama - theta2)*sin(k_1*(theta1 - theta2))*sin(theta1) - k_1*sin(theta0) + k_1*cos(k_1*(theta1 - theta2))*sin(theta1) + 2*k_1*cos(theta0)*sin(theta1) - 2*k_1*cos(theta1)*sin(theta0) + 2*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2)) + k_1*sin(gama - theta2)*cos(theta0) + k_1*sin(theta0)*cos(gama - theta2) - k_1^2*cos(theta1)*sin(k_1*(theta1 - theta2)) + M*k_1*sin(theta1) - 2*k_1^2*sin(gama - theta2)*sin(k_1*(theta1 - theta2))*sin(theta0) + sin(gama - theta2)*cos(theta0)*sin(k_1*(theta1 - theta2))*sin(theta1) - sin(gama - theta2)*cos(theta1)*sin(k_1*(theta1 - theta2))*sin(theta0) - M*k_1^2*cos(theta1)*sin(k_1*(theta1 - theta2)) + M*k_1^2*sin(k_1*(theta1 - theta2))*cos(gama - theta2) - k_1*cos(k_1*(theta1 - theta2))*cos(theta0)*sin(theta1) + k_1*cos(k_1*(theta1 - theta2))*cos(theta1)*sin(theta0) - 2*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta0) - 2*k_1*cos(k_1*(theta1 - theta2))*sin(theta0)*cos(gama - theta2) - k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta1) - k_1*cos(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2) + k_1^2*cos(theta0)*cos(theta1)*sin(k_1*(theta1 - theta2)) + M*k_1*cos(k_1*(theta1 - theta2))*sin(theta1) + k_1^2*sin(k_1*(theta1 - theta2))*sin(theta0)*sin(theta1) + 2*k_1^2*cos(theta0)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) + k_1^2*cos(theta1)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) - M*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2)) + M*k_1*sin(gama - theta2)*cos(theta1) + M*k_1*sin(theta1)*cos(gama - theta2) - M*k_1^2*cos(theta1)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) + M*k_1^2*sin(gama - theta2)*sin(k_1*(theta1 - theta2))*sin(theta1) + k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta0)*cos(theta1) + k_1*cos(k_1*(theta1 - theta2))*cos(theta0)*sin(theta1)*cos(gama - theta2) - k_1*cos(k_1*(theta1 - theta2))*cos(theta1)*sin(theta0)*cos(gama - theta2) + k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*sin(theta0)*sin(theta1) - k_1^2*cos(theta0)*cos(theta1)*sin(k_1*(theta1 - theta2))*cos(gama - theta2) + M*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*cos(theta1) + M*k_1*cos(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2) - k_1^2*sin(k_1*(theta1 - theta2))*sin(theta0)*sin(theta1)*cos(gama - theta2))/(M*l*(2*k_1 + sin(gama - theta2)*cos(theta1)*sin(k_1*(theta1 - theta2)) + sin(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2) + 2*k_1*cos(k_1*(theta1 - theta2))*cos(theta1)*cos(gama - theta2) - 2*k_1*sin(gama - theta2)*cos(k_1*(theta1 - theta2))*sin(theta1) + k_1^2*sin(gama - theta2)*cos(theta1)*sin(k_1*(theta1 - theta2)) + k_1^2*sin(k_1*(theta1 - theta2))*sin(theta1)*cos(gama - theta2)))
F=1.06;
gama=pi/F;
thetac=0:0.01:gama;
l=0.2181818;
k_1=0.3714;
M=0.8;
for k=1:numel(thetac)
theta0=thetac(k);
seqn = subs([eqn,eqn1]);
solv(k) = vpasolve(seqn,theta1,theta2);
sol(k)=solv.theta1
sol2(k)=solv.theta2
end
alpha_3=thetac./gama;
alpha_4=sol./gama-thetac./gama;
when running this code I am finding this error
Error using sym>tomupad (line 1175)
Conversion to 'sym' from 'struct' is not possible.
Error in sym (line 163)
S.s = tomupad(x);
Error in sym/privsubsasgn (line 982)
R = sym(R);
Error in sym/subsasgn (line 839)
C = privsubsasgn(L,R,inds{:});
Error in plot_alpha (line 85)
solv(k) = vpasolve(seqn,theta1,theta2);
Can anyone please help?

Best Answer

Remove the (k) on the assignment to solv. The two lines after that already pull out the two variables and you do not need to store the solutions twice. Also the next two lines assume that you are using a scalar structure which would not be the case when you are assigning to solv(k)
Once you have assigned to just solv but before pulling out the components you should check if the solution is empty. You should also check in case there were multiple solutions, which is possible if the problem just happens to simplify to a polynomial.