如何用matlab实现多项式拟合?要源代码已有数据x=[...],y=[...]离散数据

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/25 19:53:56
如何用matlab实现多项式拟合?要源代码已有数据x=[...],y=[...]离散数据

如何用matlab实现多项式拟合?要源代码已有数据x=[...],y=[...]离散数据
如何用matlab实现多项式拟合?要源代码
已有数据x=[...],y=[...]离散数据

如何用matlab实现多项式拟合?要源代码已有数据x=[...],y=[...]离散数据
我曾经写过的一个程序,
包含了画点,拟合,误差评估等
你相应的删减一些,
就能得到你需要的东西了.
希望能看的懂:
关键就一个函数:
a=polyfit(x,y,n);
请去matlab:
help polyfit
保证10分钟弄回自己的程序.
求人不如求己
% to find the least_squares fit for an input data set.
% to make a straigh line,and print it out.
% to deteming the constant m,b of y=mx+b.
%
%
clc; %clear the command window
clear;%clear all the variable has been defined
disp('----this program find the least_sqares fit of an input data set');
disp('---- as the form of y=a1*xn+a2*x(n-1)+.a(n)*x1+a(n+1)');
disp('------------starting!----------------');
%input data num
%input times of poly
x=input('enter the array of x like [1,2,3,4,.]:');
y=input('enter the array of y like [1,2,3,4,.]:');
n=input('enter times of polynomial like 2 :')
a=zeros(n+1);
%to count how many data in x
row_cloum=size(x);
m=row_cloum(2);
for i=1:1:m
plot(x(i),y(i),'bo');
hold on;
end
%calculate a
a=polyfit(x,y,n);
y_best=0;
%least squraus of ybest
%%plot the data input data as blue circles
% plot the line in red '-'
%create the fitted line of figture
xmin=min(x);
xmax=max(x);
t=xmin:0.01:xmax;
for i=1:(n+1)
y_a=(a(i)*(t.^((n+1)-i))); %element of y_poly_array
y_best=y_best+y_a; %sum them
end
% r the error array
for k=1:m
r_sum=0;
y_kbest=0;
for i=1:(n+1)
y_k(i)=(a(i)*(x(k).^((n+1)-i))); %element of y_k= ploy(xi)
y_kbest=y_kbest+y_k(i); %sum them ploy(xi)
end
r_sum=(y(k)-y_kbest)^2+r_sum;
end
%the poly is:
disp('the poly is y=a1*xn+a2*x(n-1)+.a(n)*x1+a(n+1):')
disp('and the array A is A=:');
disp(a);
disp('the (y_best-y)^2 is R= :')
disp(r_sum);
%figture
ymin=min(y_best);
ymax=max(y_best);
axis=([xmin,xmax,ymin,ymax]);
%set plot settings
%add a title and legend
plot(t,y_best,'r-','LineWidth',2);
%hold off;
title('\bf least-squares fit y=a1*xn+a2*x(n-1)+.a(n)*x1+a(n+1)');
xlabel('\bf\itx');
ylabel('\bf\ity');
legend('input data','fitted line',4);
grid on;
print -dtiff lsq_fit.tif;

如何用matlab实现多项式拟合?要源代码已有数据x=[...],y=[...]离散数据 编写MATLAB程序实现多项式拟合 如何用Origin进行多项式拟合 如何用matlab进行拟合,用最小二乘法? 最小二乘法用一个多项式函数拟合多个多项式函数用最小二乘法拟合,如何用matlab实现啊?matlab里面有现成的函数么?我看大多是点拟合曲线的.比如y1=a1*x^2+a2*x+a3,y2=b1*x^2+b2*x+b3,其中b1,b2,b3,a1,a2,a3 matlab 多变量拟合(急)如何用matlab进行 多变量拟合 如何用matlab求拟合的函数中的参数? 如何用matlab制作散点图并进行函数拟合 如何在matlab中确定多项式拟合的阶数 matlab级数求和如何用sum实现? 如何用MATLAB实现,1.-140 MATLAB怎样搞多项式拟合 matlab 怎样实现拉格朗日插值拟合? 已知4个点,请问如何用Matlab进行3次多项式拟合成曲线?x=[220 280 340 400];y=[101 70.5 51 24]; 各位MATLAB高手,如何用MATLAB拟合2维正态分布在MATLAB里应该怎么样实现2个正态分布相乘呢..本人刚刚接触MATLAB..请各位指点 谢谢.. 如何用2、3、4、6阶多项式拟合函数?(MATLAB)分别用2、3、4、6阶多项式拟合函数y=cosx,并做出拟合曲线与函数曲线 进行比较,并分析结果.(我们老师让用MATLAB做课程设计,我没用过这个软件,希望 请问matlab cftool工具箱如何进行三元拟合?我有三个变量,x1,x2,y,请问如何用cftool拟合? matlab多项式二次拟合如何检验误差