Régression non linéaire
%----------------------------------------------------------------- % régression non linéaire par moindres carrés % d'aprés 'Apprendre et maitriser Matlab' % % approximation lny = ln a + (b*x) % voir explications moindres carrés dans le fichier reg_lin.m %----------------------------------------------------------------- clear all; echo on; %régression non linéaire % ex : x =[0.1 0.2 0.5 1.0 1.5 1.9 2.0 3.0 4.0 6.0]; % y =[0.95 0.89 0.79 0.7 0.63 0.58 0.56 0.45 0.36 0.28]; echo off; x =[0.1 0.2 0.5 1.0 1.5 1.9 2.0 3.0 4.0 6.0]; y =[0.95 0.89 0.79 0.7 0.63 0.58 0.56 0.45 0.36 0.28]; %matrice H n=length(x); H=[ones(n,1) x']; % x' : transposée de x bb=log(y); Y=bb'; % Y = transposée de bb % teta tel que Y= H . teta teta=inv(H'*H)*H'*Y; %coefficients a=exp(teta(1,1)); b=teta(2,1); ym=a*exp(b*x); %modèle exponentiel clf; plot(x,y,'+'); hold on; plot(x,y); plot(x,ym,'r'); posX1=1; posX2=5; text(x(posX1),y(posX1),'mesures'); text(x(posX2),ym(posX2),'modèle'); str=sprintf('régression exponentielle (moindres carrés)'); str1=sprintf(' ym=%0.5g*exp(%0.5g*x)',a,b ); str2=strcat(str,str1); title(str2); grid;
Dernière Modification : Lun 19 Mars 2007 13:28
Copyright © 1999-2010 Jean-Paul Molina Tous droits réservés.