matlab已知两点的坐标和第三点到两点的距离求第三点坐标怎么编程求解? 50
syms x1 y1 x2 y2 x y s1 s2;
eq1 = (x-x1)^2+(y-y1)^2-s1*s1;
eq2 = (x-x2)^2+(y-y2)^2-s2*s2;
sol = solve(eq1,eq2,x,y);
x=simplify(sol.x);
y=simplify(sol.y);
x1=0,y1=16.2361,s1=7.7;
x2=8,y2=0,s2=11.8;
x=eval(x)
y=eval(y)
%输出:
% x =
% -0.1456
% 6.1933
% y =
% 8.5375
% 11.6609
df = dataframe('dataframe1.csv');%#输入放在dataframe1.csv里
%#octave dataframe is still to be finished
df = readtable('dataframe1.csv');%输入放在dataframe1.csv里
ans3=solve((x1(i)-x).^2+(y1(i)-y).^2-s1(i).^2,(x2(i)-x).^2+(y2(i)-y).^2-s2(i).^2);
df(i,['x4'])={ans3.x(2)};
end
try
writetable('df2.csv',df);%结果放在df2.csv里
catch
clear;
clc;
%% 设置导入选项
opts = spreadsheetImportOptions("NumVariables", 2);
% 指定工作表和范围
opts.Sheet = "Sheet1";
opts.DataRange = "A2:B8"; % 选择取值范围
% 指定列名称和类型
opts.VariableNames = ["s1", "s2"];
opts.VariableTypes = ["double", "double"];
% 导入数据
tbl = readtable("C:\Users\pc\Desktop\data.xlsx", opts, "UseExcel", false); %选择文件(数据)路径
%% 转换为输出类型
s1 = tbl.s1;
s2 = tbl.s2;
%% 清除临时变量
clear opts tbl
syms x1 x2 y1 y2;
X = [];
Y = [];
x1 = 0;
y1 = 16.2361; %(x1,y1)不变
x2 = 8;
y2 = 0; %(x2,y2)不变
[m,n] = size(s1);
for i = 1:m
syms x y;
sx = s1(i);
sy = s2(i);
[x,y] = vpasolve((x-x1)^2+(y-y1)^2-(sx)^2,(x-x2)^2+(y-y2)^2-(sy)^2); %二元二次方程组
X = [X;x(1)];
X = [X;x(2)];
Y = [Y;y(1)];
Y = [Y;y(2)];
% 检查求得的坐标是否符合
S1 = (x(1)-x1)^2+(y(1)-y1)^2-(sx)^2
T1 = (x(1)-x2)^2+(y(1)-y2)^2-(sy)^2
if (S1 == 0.0 && T1 == 0.0)
disp('i=')
disp(i) %i 表示Excel中第i个要求的点
disp('次i对应点符合,(x,y)') % 第i个点的坐标
disp(x(1))
disp(y(1))
else
disp('不符合')
end
S2 = (x(2)-x1)^2+(y(2)-y1)^2-(sx)^2
T2 = (x(2)-x2)^2+(y(2)-y2)^2-(sy)^2
if (S2 == 0.0 && T2 == 0.0)
disp('i=')
disp(i)
disp('此i对应点符合,(x,y)')
disp(x(2))
disp(y(2))
else
disp('不符合')
end
end