Régression non linéaire
%----------------------------------------------------------------------- % régression non linéaire % d'aprés 'Apprendre et maitriser Matlab' % % approximation y = a exp(b*x) % relations de Newton % Somme(x lny)-Somme(x)Somme(lny / n) % b= ------------------------------------- % Somme(x²) - (Somme(s))²/n % % Somme( exp(bx) / y ) % a= ---------------------- % Somme(exp(2bx) / y²) 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]; n=length(x); b=( sum(x.*log(y))-sum(x)*sum(log(y)/n) )/( sum(x.^2)-sum(x)^2/n ); a=sum( exp(b*x)./y )/sum( exp(2*b*x)./y.^2 ); ym=a*exp(b*x); % modêle 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 '); 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.