Can't get the solution on this nonlinear system of equations using vpasolve

조회 수: 1 (최근 30일)
Hi, so i'm trying to find solutions for E1 and E2, but sadly it doesn't show me an answer
clc
clear all
Px=[6.56044 -4.12471 -19.6017 -18.2934 -1.8923 21.1196 17.6706];
Py=[0.995643 0.00147957 1.14159 2.07962 6.30745 11.3302 4.55826];
L=82.4;
l1=35.7;
L2=39.7;
for j=1:7
PX(j)=-Px(j);
PY(j)=L-Py(j);
end
j=1
syms X1 X2
E1=l1*cos(X1)+L2*cos(X2)-PX(1);
E2=l1*sin(X1)+L2*sin(X2)-PY(1);
Y=vpasolve([E1,E2],[X1,X2]),[1.5,1.7]
A=Y.X1
B=Y.X2

채택된 답변

Torsten
Torsten 2022년 6월 24일
편집: Torsten 2022년 6월 24일
For that your two equations can have a solution, one can show that
abs((PX^2+PY^2-l1^2-L2^2)/(2*l1*L2))
must be <= 1.
This is only the case for i=6, and for this case, vpasolve gives a solution.
Px=[6.56044 -4.12471 -19.6017 -18.2934 -1.8923 21.1196 17.6706];
Py=[0.995643 0.00147957 1.14159 2.07962 6.30745 11.3302 4.55826];
L=82.4;
l1=35.7;
L2=39.7;
syms X1 X2
x1 = zeros(7,1);
x2 = zeros(7,1);
for i=1:7
PX(i)=-Px(i);
PY(i)=L-Py(i);
value = abs((PX(i).^2+PY(i).^2-l1^2-L2^2)/(2*l1*L2))
if value > 1
continue
end
E1 = l1*cos(X1)+L2*cos(X2)-PX(i) == 0;
E2 = l1*sin(X1)+L2*sin(X2)-PY(i) == 0;
Y = vpasolve([E1,E2],[X1,X2]);
Y.X1
Y.X2
x1(i) = Y.X1;
x2(i) = Y.X2;
end
value = 1.3473
value = 1.3956
value = 1.4593
value = 1.3884
value = 1.0383
value = 0.9336
ans = 
1.6665945097644129747979749283503
ans = 
2.0330490977381021058751812658667
value = 1.2422
  댓글 수: 5
Torsten
Torsten 2022년 6월 24일
편집: Torsten 2022년 6월 24일
Here is a least-squares solution. The array "error" indicates how good the two equations could be solved.
Px=[6.56044 -4.12471 -19.6017 -18.2934 -1.8923 21.1196 17.6706];
Py=[0.995643 0.00147957 1.14159 2.07962 6.30745 11.3302 4.55826];
L=82.4;
l1=35.7;
L2=39.7;
%syms X1 X2
x1 = zeros(7,1);
x2 = zeros(7,1);
error = zeros(7,1);
for i=1:7
PX(i)=-Px(i);
PY(i)=L-Py(i);
%value = abs((PX(i).^2+PY(i).^2-l1^2-L2^2)/(2*l1*L2))
%if value > 1
% continue
%end
fun = @(x)[l1*cos(x(1))+L2*cos(x(2))-PX(i),l1*sin(x(1))+L2*sin(x(2))-PY(i)];
[x,fval] = lsqnonlin(fun,[1,2],[0 0],[2*pi,2*pi]);
%E1 = l1*cos(X1)+L2*cos(X2)-PX(i) == 0;
%E2 = l1*sin(X1)+L2*sin(X2)-PY(i) == 0;
%Y = vpasolve([E1,E2],[X1,X2]);
%Y.X1
%Y.X2
%x1(i) = Y.X1;
%x2(i) = Y.X2;
x1(i) = x(1);
x2(i) = x(2);
error(i) = fval;
end
Local minimum possible. lsqnonlin stopped because the size of the current step is less than the value of the step size tolerance. Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance. Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance. Local minimum possible. lsqnonlin stopped because the size of the current step is less than the value of the step size tolerance. Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance. Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
error
error = 7×1
39.2914 50.4340 67.0631 48.6821 0.5128 0.0000 19.5560
x1
x1 = 7×1
1.6512 1.5208 1.3341 1.3469 1.5459 1.6666 1.7940
x2
x2 = 7×1
1.6512 1.5208 1.3341 1.3469 1.5459 2.0330 1.7940
José David Castillo Blanco
José David Castillo Blanco 2022년 6월 24일
Thanks, just for the record I had an error on the value "l1", also, due to uncertainty in measurement the tolerance can't be too tight.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by