my solve cant work again

1 view (last 30 days)
cehua liu
cehua liu on 8 Jun 2023
Commented: cehua liu on 8 Jun 2023
clc;clear;close all;
s_length=0.125;
m=0;n=0;
a=-s_length/4+m%location of a (x=-0.03125,y=0);
b=s_length/4+n %location of b (x= 0.03125,y=0);
x1=5;y1=8; %location of c;
lac85=sqrt((x1-a).^2+(y1).^2);%distance of ac;
lbc85=sqrt((x1-b).^2+(y1).^2);%distance of bc;
dl85=lac85-lbc85;
x2=-4;y2=4; %location of c;
lac44=sqrt((x2-a).^2+(y2).^2);
lbc44=sqrt((x2-b).^2+(y2).^2);
dl44=lac44-lbc44;
syms a1 b1
eq1= sqrt((x1-a1).^2+(y1).^2)-sqrt((x1-b1).^2+(y1).^2)==dl85;%establish an equation using the difference of two distances
eq2= sqrt((x2-a1).^2+(y2).^2)-sqrt((x2-b1).^2+(y2).^2)==dl44;
[a1,b1]=solve(eq1,eq2,a1,b1,'Real', true);
double(a1)
double(b1)
%%%%%%%%%%%%%%%%%%%%%%%%%%the error
警告: Possibly spurious solutions.
警告: Solutions are parameterized by the symbols: x. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
警告: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
错误使用 symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
Xstr = mupadmex('symobj::double', S.s, 0);

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 8 Jun 2023
Edited: Dyuman Joshi on 8 Jun 2023
You can use vpasolve to solve the equation numerically -
format long
s_length=0.125;
m=0;n=0;
a=-s_length/4+m %location of a (x=-0.03125,y=0);
a =
-0.031250000000000
b=s_length/4+n %location of b (x= 0.03125,y=0);
b =
0.031250000000000
x1=5;y1=8; %location of c;
lac85=sqrt((x1-a).^2+(y1).^2);%distance of ac;
lbc85=sqrt((x1-b).^2+(y1).^2);%distance of bc;
dl85=lac85-lbc85;
x2=-4;y2=4; %location of c;
lac44=sqrt((x2-a).^2+(y2).^2);
lbc44=sqrt((x2-b).^2+(y2).^2);
dl44=lac44-lbc44;
syms a1 b1
eq1= sqrt((x1-a1).^2+(y1).^2)-sqrt((x1-b1).^2+(y1).^2)==dl85;%establish an equation using the difference of two distances
eq2= sqrt((x2-a1).^2+(y2).^2)-sqrt((x2-b1).^2+(y2).^2)==dl44;
%Using vpasolve instead of solve
[a1,b1] = vpasolve(eq1,eq2,a1,b1)
a1 = 
b1 = 
0.031250000000113565406372863339127
double(a1)
ans =
-0.031249999999886
double(b1)
ans =
0.031250000000114
You can also define a1 and b1 to be real from start, in that case, solve() will return a solution via vpasolve() as well, as it is unable to find a symbolic solution.
syms a1 b1 real

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!