What is wrong with my code?

1 次查看(过去 30 天)
function y = slider(x,x2)
x0 = [3;60];
L2 = 2;
L1 = 4;
x2= 50;
y = [L2*cosd(x2) - x(1)*cosd(x(2)) - L1;
L2*sind(x2) - x(1)*sind(x(2))];
end
>> x_full = fsolve(@slider,x0);
>> Rao4 = x_full(1)
Rao4 =
-3.116953357712931
>> theta4 = x_full(2)
theta4 =
-29.441463984624214
It is a equation position for slide crank. The answer for Rao4 should be positive and theta 4 should be around 50 degrees, I try it many times but I don't know what is wrong. I checked with my friend's code, it's the same but still, we have different result. Thank you for your help.

回答(1 个)

Walter Roberson
Walter Roberson 2019-3-4
Your equation has an infinite number of solutions because of the trig, and has two basic forms. You are getting the primary solution to one of the basic forms. If you were to use different x0 you might end up with a different solution.
However, none of the infinite solutions has x(2) near 50 degrees: one of the solutions has an x(2) near 150.56 degrees though. The x(2) values are basically 180 degrees apart from that -29.4 that you produced.
  2 个评论
Khoirunnisa' Irodatillah
Ah.. I see.. How to make the answer only form 0 to 2pi? Thank you for your answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by