The following error occurred converting from sym to double: Unable to convert expression containing symbolic variables into double array..

6 views (last 30 days)
I'm solving the problem with a long formula. There is no problem with other parts, but it seems that the problem occurs in the above code. How can I solve this problem? The problem continues to occur even after using 'subs'
can anyone help me please.....?
ERROR
symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs'
function first to substitute values for variables.
l1= 50;
l2= 50;
l3= 10;
x2 = l1*cos(theta1);
Unrecognized function or variable 'theta1'.
x3 = l2*cos(theta1+theta2)+ x2;
y2 = l1*sin(theta1);
y3 = l2*sin(theta1+theta2)+ y2;
a = acosd((l1^2 + l2^2 - (sqrt(x3^2 + y3^2))^2 )/(2*l1*l2));
B = acosd((l1^2 + (sqrt(x3^2 + y3^2))^2 - l2^2 )/(2*l1*(sqrt(x3^2 + y3^2))));
theta1 = atan2d(y3,x3)+B;
theta2 = -(180-a);
theta3 = - theta1 - theta2;
for i=[1:100]
k=dt*i;
th1(i)=double(subs(theta1,t,k)); % error point
th2(i)=double(subs(theta2,t,k));
th3(i)=double(subs(theta3,t,k));
end
t=[0.01:0.1:10];
figure(1)
hold on
plot(t,th1);
plot(t,th2);
plot(t,th3);
title('theta')
legend('theta1','theta2','theta3')
hold off
  1 Comment
Walter Roberson
Walter Roberson on 25 Nov 2022
x2 = l1*cos(theta1);
theta1 is not defined
x3 = l2*cos(theta1+theta2)+ x2;
You use theta1 to define x3 and other variables
theta1 = atan2d(y3,x3)+B;
If theta1 exists, then you overwrite theta1 with a new value (if it does not exist, you would not have gotten this far.)
If you are trying to define a balance equation, with x2, x3, y3 being defined in theta1 and simultaneously theta1 must have that particular value in terms of variables defined by theta1, then you need to create an equation, like
eqn = theta1 == atan2d(y3, x3) + B
and solve the eqn

Sign in to comment.

Accepted Answer

VBBV
VBBV on 25 Nov 2022
syms theta1 theta2
t=[0.01:0.1:10];
l1= 50;
l2= 50;
l3= 10;
dt = 1;
x2 = l1*cos(theta1)
x2 = 
x3 = l2*cos(theta1+theta2)+ x2;
y2 = l1*sin(theta1);
y3 = l2*sin(theta1+theta2)+ y2;
a = acosd((l1^2 + l2^2 - (sqrt(x3^2 + y3^2))^2 )/(2*l1*l2));
B = acosd((l1^2 + (sqrt(x3^2 + y3^2))^2 - l2^2 )/(2*l1*(sqrt(x3^2 + y3^2))));
t1 = atan2d(y3,x3)+B;
t2 = -(180-a);
t3 = - theta1 - theta2;
for i=[1:100]
k=dt*i;
y1 = subs(t1,{theta1,theta2},{k,k});
y2 = subs(t2,{theta1,theta2},{k,k});
y3 = subs(t3,{theta1,theta2},{k,k});
th1(i)=double(y1); % error point
th2(i)=double(y2);
th3(i)=double(y3);
end
figure(1)
hold on
plot(t,th1);
plot(t,th2);
plot(t,th3);
title('theta')
legend('theta1','theta2','theta3')
hold off
  1 Comment
VBBV
VBBV on 25 Nov 2022
Edited: VBBV on 25 Nov 2022
In the below lines, theta1 expression includes both symbolic variables, theta1 and theta2, and its not given a numeric substitution, so it gives error
th1(i)=double(subs(theta1,t,k)); % error point
th2(i)=double(subs(theta2,t,k));
th3(i)=double(subs(theta3,t,k));

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!