Effacer les filtres
Effacer les filtres

error using vpasolve-Conversion to 'sym' from 'struct' is not possible.

2 vues (au cours des 30 derniers jours)
safisay
safisay le 21 Déc 2017
Commenté : Walter Roberson le 21 Déc 2017
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Déc 2017
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.
  2 commentaires
safisay
safisay le 21 Déc 2017
thanks Walter.
Is it possible to use any other solver rather than vpasolve? it seems like some of the solutions are not correct.
Walter Roberson
Walter Roberson le 21 Déc 2017
Your equations turn out to be equivalent. If you subtract the two equations from each other, and then subs() theta2 for theta1 on the right hand side, the right hand side simplifies to 0, so theta1 - theta2 = 0 so theta1 == theta2
Your equations have multiple solutions because of the symmetry of sin(). Which solution you get depends upon where vpasolve() happens to probe. You can tell vpasolve() where to solve, using
vpasolve(seqn, [theta1;theta2], [5;5])
here the 5;5 is the starting point for theta1 and theta2.
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 = vpasolve(seqn,[theta1;theta2],[0 2*pi;0 2*pi]);
if isempty(solv) || isempty(solv.theta1)
fprintf('Warning, found no solutions for k = %d, theta0 = %g\n', k, theta0);
sol(k) = sym(nan);
sol2(k) = sym(nan);
else
if length(solv.theta1) > 1
fprintf('Warning, found %d solutions for k = %d, theta0 = %g, taking first of them\n', length(solv), k, theta0);
end
sol(k) = solv.theta1(1);
sol2(k) = solv.theta2(1);
end
end
alpha_3 = thetac./gama;
alpha_4 = sol./gama-thetac./gama;
plot(thetac,alpha_4);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Partial Differential Equation Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by