필터 지우기
필터 지우기

What is wrong with my code?

조회 수: 1 (최근 30일)
Khoirunnisa' Irodatillah
Khoirunnisa' Irodatillah 2019년 3월 4일
댓글: Walter Roberson 2019년 3월 5일
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
Khoirunnisa' Irodatillah 2019년 3월 5일
Ah.. I see.. How to make the answer only form 0 to 2pi? Thank you for your answer.
Walter Roberson
Walter Roberson 2019년 3월 5일
Or use the symbolic toolbox. vpasolve() permits you to specify bounds for variables.

댓글을 달려면 로그인하십시오.

카테고리

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