作业帮 > 综合 > 作业

怎么用matlab代码拟合椭圆?

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/06/24 17:21:59
怎么用matlab代码拟合椭圆?
离散点拟合椭圆,求matlab代码,要确定可以用的!
怎么用matlab代码拟合椭圆?
clear; clc; close all;
% 设出圆锥曲线方程
F=@(p,x)p(1)*x(:,1).^2+p(2)*x(:,1).*x(:,2)+p(3)*x(:,2).^2+p(4)*x(:,1)+p(5)*x(:,2)+p(6);
% 离散数据点
x=[1.7729 1.9228
1.7338 1.9072
2.0539 1.6137
2.0656 1.6412
1.8611 1.48765
1.9005 1.4971
2.0732 1.6546
1.8338 1.9405
1.9375 1.5104
1.6878 1.5177
1.7031 1.5097
1.9577 1.5201
1.9872 1.5437
2.0341 1.5805
2.0723 1.6546
2.0681 1.8284
2.0557 1.8483
2.0491 1.5651
];
p0=[1 1 1 1 1 1];
warning off
% 拟合系数,最小二乘方法
p=nlinfit(x,zeros(size(x,1),1),F,p0);
plot(x(:,1),x(:,2),'ro');
hold on;
xmin=min(x(:,1));
xmax=max(x(:,1));
ymin=min(x(:,2));
ymax=max(x(:,2));
% 作图
ezplot(@(x,y)F(p,[x,y]),[-1+xmin,1+xmax,-1+ymin,1+ymax]);
title('曲线拟合');
legend('样本点','拟合曲线')
再问: 还有这误差怎么确定?能否再麻烦一下