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!