码迷,mamicode.com
首页 > 其他好文 > 详细

matlab多项式拟合以及指定函数拟合

时间:2015-03-10 13:33:08      阅读:603      评论:0      收藏:0      [点我收藏+]

标签:

clc;
clear all;
close all;
%% 多项式拟合指令;
% X = [1 2 3 4 5 6 7 8 9 ];
% Y = [9 7 6 3 -1 2 5 7 20];
% P= polyfit (X,Y,3);
%
% x = 0:2:10;
% y = polyval(P,x);
% plot(x,y,X,Y,‘r*‘);
%% 指定函数拟合
x=[ 0;0.4;1.2; 2;2.8;3.6;4.4;5.2; 6;7.2; 8;9.2;10.4;11.6;12.4;13.6;14.4;15];
y=[ 1;0.85;0.29;-0.27;-0.53;-0.4;-0.12;0.17;0.28;0.15;-0.03;-0.15;-0.071;0.059; 0.08;0.032;-0.015;-0.02];
plot(x,y,‘r*‘)
hold on
f = fittype(‘a*cos(k*t)*exp(w*t)‘,‘independent‘,‘t‘,‘coefficients‘,{‘a‘,‘k‘,‘w‘});
cfun = fit(x,y,f);
xi = 0:1:20;
yi = cfun(xi);
plot(xi,yi,‘b-‘)
%程序中,函数fittype是自定义拟合函数;cfun=fit( x, y, f)是根据自定义的拟合函数f 来拟合数据 x

 

matlab多项式拟合以及指定函数拟合

标签:

原文地址:http://www.cnblogs.com/Kermit-Li/p/4325614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!