Can't get the solution on this nonlinear system of equations using vpasolve
조회 수: 1 (최근 30일)
이전 댓글 표시
José David Castillo Blanco
2022년 6월 23일
댓글: José David Castillo Blanco
2022년 6월 24일
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
댓글 수: 0
채택된 답변
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
댓글 수: 5
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
error
x1
x2
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!