I am looking to solve for the three theta's using sys in an array. How should my code look to make this happen. Heres what I have:

1 次查看(过去 30 天)
syms theta1 theta2 theta3
eq1 = theta1 == 90-asin((L1-hblock_sub-h_ram-L3*sin(theta2)-L4*sin(theta3))/L5);
eq2 = theta2 == acos(-(L6-L4*cos(theta3)-L5*cos(90-theta1))/L3);
eq3 = theta3 == acos((L6+L3*cos(theta2)-L5*cos(90-theta1))/L4);
sol = solve([eq1 eq2 eq3],[theta1 theta2 theta3]);
hblock = subs(sol.theta1,theta2,theta3);hblock_sub = double(hblock_sub);
  1 个评论
Torsten
Torsten 2023-3-10
编辑:Torsten 2023-3-10
Replace 90 by pi/2.
I don't think this will solve your problem, but it's an error in your equations.
Even better:
Use sin(pi/2-x) = cos(x) and cos(pi/2-x) = sin(x).

请先登录,再进行评论。

回答(1 个)

Shushant
Shushant 2023-3-13
From my understanding of your issue, you are trying to solve a set of equations but instead of declaring "theta1", "theta2" and "theta3" separately you want to declare them as part of an array. To accomplish this, you can look through this documentation here. I have tried to implement the same using some random values below.
syms theta [1 3]
L1 = 1;
L2 = 2;
L3 = 3;
L4 = 4;
L5 = 5;
L6 = 6;
hblock_sub = 1;
h_ram = 1;
eq1 = theta1 == 90-asin((L1-hblock_sub-h_ram-L3*sin(theta2)-L4*sin(theta3))/L5);
eq2 = theta2 == acos(-(L6-L4*cos(theta3)-L5*cos(90-theta1))/L3);
eq3 = theta3 == acos((L6+L3*cos(theta2)-L5*cos(90-theta1))/L4);
sol = solve([eq1 eq2 eq3],[theta1 theta2 theta3])
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
sol = struct with fields:
theta1: 91.09127337359374229308322484689 + 0.014498593097431429385469218902618i theta2: 1.4767379109122526840455134003504 + 0.022557641373024566759457348260003i theta3: 0.11249516403464522396375288111294 + 0.0068154950806834305011949243139886i
hblock = subs(sol.theta1,theta2,theta3)
hblock = 
hblock_sub = double(hblock_sub)
hblock_sub = 1

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by