solving 4 equation with 4 unkowns

조회 수: 2 (최근 30일)
Omar H.
Omar H. 2020년 4월 6일
댓글: Omar H. 2020년 4월 6일
good evening
i've been trying to solve these 4 equations using fsolve but the error Index exceeds array bounds. Kept appearing.
i've read multiple posts with the same problem but i couldn' solve the problem
is there anything wrong in the equations that i haven't noticed ?
thanks for the help
function F = myfun(x)
F = [
x(4) -135 +x(2);
130*cos(x(1)) - 31.7*cos(x(2)) - 140*cos(x(3)) - 146.4*cos(172.15);
130*sin(x(1)) - 31.7*sin(x(2)) - 140*sin(x(3)) - 146.4*sin(172.15);
-45*cos(x(4)) + 70*cos(x(5)) - 140*cos(x(3)) - 53.85*cos(68.198);
-45*sin(x(4)) + 70*sin(x(5)) - 140*sin(x(3)) - 53.85*sin(68.198);
];
end
  댓글 수: 2
Lubos Smolik
Lubos Smolik 2020년 4월 6일
Could you also provide your main script? It appears that there are 5 equations in your function.
Omar H.
Omar H. 2020년 4월 6일
thank you for commenting Lubos smolik
i'm a new user and i'm still learning.
i'm trying to solve a problem in one of my classes there are 5 unknowns and 4 equations
r2cos(x1) - r3cos(x2) - r4cos(x3) - r1cos(x10)
r2sin(x1) - r3sin(x2) - r4sin(x3) - r1sin(x10)
r5cos(x4) - r6cos(x5) - r4cos(x3) - r7cos(x11)
r5sin(x4) - r6sin(x5) - r4sin(x3) - r7sin(x11)
Where r2=130 r3=3.7 r4=140 r1=146.4 x10=172.15 r5=45 r6=70 r7=53.85 x11=68.198
and a fifth one between
x(4) = x(2) + 135

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

답변 (1개)

darova
darova 2020년 4월 6일
It's because of the way you concantenate your equations
Example of two different declarations
[1 - 2]
ans =
-1
[1 -2]
ans =
1 -2
Better practice would be:
F = zeros(5,1);
F(1) = x(4) -135 +x(2);
F(2) = 130*cos(x(1)) - 31.7*cos(x(2)) - 140*cos(x(3)) - 146.4*cos(172.15);

카테고리

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