⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fitpoly.m

📁 nnToolKit 神经网络工具包是基于 MATLAB 神经网络工具箱自行开发的一组神经网络算法函数库
💻 M
字号:
function retstr = FitPoly(ModelNo,NetPara,SeqData,TargetData,DataDir)
NNTWARN OFF

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ModelNo='1';
%DataDir='.';        %表示当前目录
%NetPara(1)=11;
%NetPara(2)=3;
%NetPara(3)=100;

%SeqData = (1900:10:2000);

%TargetData = [75.995 91.972 105.711 123.203 131.669 ...
%     150.697 179.323 203.212 226.505 249.633 281.422];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%保留原目录
olddir=pwd;

%进入数据所在目录
cd(DataDir);


InputDim=NetPara(1);       %样本组数
FitFact=NetPara(2);        %拟合阶数
DataNum=NetPara(3);        %拟合据数点数

x = SeqData;
y = TargetData;

% [P,S,MU] = POLYFIT(X,Y,N) finds the coefficients of a polynomial
%    in XHAT = (X-MU(1))/MU(2) where MU(1) = mean(X) and MU(2) = std(X).
%    This centering and scaling transformation improves the numerical
%    properties of both the polynomial and the fitting algorithm.
% The structure S contains the Cholesky factor of the Vandermonde
%    matrix (R), the degrees of freedom (df), and the norm of the
%    residuals (normr) as fields. 
[coef,s,mu]=polyfit(x,y,FitFact);
[coef]=polyfit(x,y,FitFact);

%将参数值写入文件coefficient
fcoef=fopen(sprintf('coef%s%s',ModelNo,'.dat'),'w');
fsnormr=fopen(sprintf('snormr%s%s',ModelNo,'.dat'),'w');
fxhat=fopen(sprintf('xhat%s%s',ModelNo,'.dat'),'w'); 

%多项式拟合系数
fprintf(fcoef,'%25.15f ',coef);
%残差
fprintf(fsnormr,'%15.8f ',s.normr);
%各点误差
fprintf(fxhat,'%10.6f ',(x-mu(1))/mu(2));

fclose(fcoef);
fclose(fsnormr);
fclose(fxhat);

cd(olddir);

retstr=1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -