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.
댓글 수: 0
답변 (1개)
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
Walter Roberson
2019년 3월 5일
See https://www.mathworks.com/matlabcentral/answers/106715-how-to-add-a-constraint-condition-to-fsolve
Or use the symbolic toolbox. vpasolve() permits you to specify bounds for variables.
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!