%===================================================== % % MOS21 - 2013 % % Minimisation de l'Ed de 2 ressorts par dichotomie. % %===================================================== %=== nettoyage de matlab clc; clear all; close all; %=== parametres L=2; L1=1.5; L2=1.2; k1=10; k2=15; x_exact=(k1*L1+k2*L-k2*L2)/(k1+k2); n=100;%nb points tracés Ed(x) epsilon_cvg=1E-8; %=== courbes Ed(x) Edp(x) table_x=zeros(n,1); table_Ed=zeros(n,1); table_Edp=zeros(n,1); for i=1:n xi=(i-1)*L/(n-1); table_x(i,1)=xi; table_Ed(i,1)=Ed(xi,k1,k2,L1,L2,L); table_Edp(i,1)=Edp(xi,k1,k2,L1,L2,L); end figure(1) hold on plot(table_x,table_Ed,'-b','markersize',10,'linewidth',2); plot(x_exact,Ed(x_exact,k1,k2,L1,L2,L),'rx','markersize',10,'linewidth',2); grid; xlabel('x'); ylabel('E(x)'); legend('energie de deformation p/r x','minimum analytique'); hold off figure(2) hold on plot(table_x,table_Edp,'-g','markersize',10,'linewidth',2); plot(x_exact,Edp(x_exact,k1,k2,L1,L2,L),'rx','markersize',10,'linewidth',2); grid; xlabel('x'); ylabel('dE(x)/dx'); legend('derivee de l energie de deformation p/r x','zero analytique'); hold off %=== algo dichotomie xG=0; xC=L/2; xD=L; compteur=1; test_fin=0; while(test_fin==0) fG=Edp(xG,k1,k2,L1,L2,L); fC=Edp(xC,k1,k2,L1,L2,L); fD=Edp(xD,k1,k2,L1,L2,L); h3=figure(3); hold on plot(table_x,table_Edp,'-g','markersize',10,'linewidth',2); plot(x_exact,Edp(x_exact,k1,k2,L1,L2,L),'rx','markersize',10,'linewidth',2); plot([xG,xD],[fG,fD],'ko','markersize',10,'linewidth',2); grid; xlabel('x'); ylabel('E(x)'); legend('energie de deformation p/r x','minimum analytique','bornes dichotomie'); hold off input('pour continuer presser ENTER'); close(h3); if(fG*fC<0) xG=xG; xD=xC; xC=(xG+xD)/2; else xG=xC; xD=xD; xC=(xG+xD)/2; end if(abs(xG-xD) xG=%f\n-> xD=%f\n',compteur,xG,xD); compteur=compteur+1; end figure(3) hold on plot(table_x,table_Edp,'-g','markersize',10,'linewidth',2); plot(x_exact,Edp(x_exact,k1,k2,L1,L2,L),'rx','markersize',10,'linewidth',2); plot(xC,Edp(xC,k1,k2,L1,L2,L),'ro','markersize',10,'linewidth',2); grid; xlabel('x'); ylabel('dE(x)/dx'); legend('derivee de l energie de deformation p/r x','zero analytique','zero par dichotomie'); hold off figure(4) hold on plot(table_x,table_Ed,'-b','markersize',10,'linewidth',2); plot(x_exact,Ed(x_exact,k1,k2,L1,L2,L),'rx','markersize',10,'linewidth',2); plot(xC,Ed(xC,k1,k2,L1,L2,L),'ro','markersize',10,'linewidth',2); grid; xlabel('x'); ylabel('E(x)'); legend('energie de deformation p/r x','minimum analytique','minimum par dichotomie'); hold off