i want to solve x1 and x2 about a=0:0.01:2*pi
this is my error code
======================================
clear all; clc
ct=1;l2=2.1; l1=2.5; r=0.7; z=5.5; d=1.2; h=1.8;
for a=0:0.01:2*pi
x(ct)=fsolve(@bicycle,[1,0]);
ct=ct+1;
end
==========================
function F = bicycle(x)
l2=2.1; l1=2.5; r=0.7; z=5.5; d=1.2; h=1.8;
F(1) = l1*sin(x(1))-l2*sin(x(2))-d-r*cos(a);
F(2) = z-l1*cos(x(1))-l2*cos(x(2))-h-r*sin(a);
end
how can i solve x1 and x2?

 채택된 답변

Star Strider
Star Strider 2019년 5월 13일

1 개 추천

Youi need to pass ‘a’ as a parameter to your ‘bicycle’ function.
Try this:
function F = bicycle(x,a)
l2=2.1; l1=2.5; r=0.7; z=5.5; d=1.2; h=1.8;
F(1) = l1*sin(x(1))-l2*sin(x(2))-d-r*cos(a);
F(2) = z-l1*cos(x(1))-l2*cos(x(2))-h-r*sin(a);
end
l2=2.1; l1=2.5; r=0.7; z=5.5; d=1.2; h=1.8;
a=0:0.01:2*pi;
for ct = 1:numel(a)
x(ct,:)=fsolve(@(x)bicycle(x,a(ct)),[1,0]);
end
figure
plot(a, x)
grid
xlabel('a')
ylabel('Root')
legend('F_1', 'F_2', 'Location','N')
The Plot —
how to play fsolve using for loop - 2019 05 13.png

댓글 수: 3

Jong Rok Lee
Jong Rok Lee 2019년 5월 14일
Thank you so much!
i can do my work thanks to you~
God bless you
Star Strider
Star Strider 2019년 5월 14일
As always, my pleasure!
Thank you.
muchas gracias me sirvio mucho el ejemplo para encontrar todas las posiciones de un mecanismo de 4 barras

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by