Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EPS=input('EPS=');
- xi=input('xi=');
- xf=input('xf=');
- while xi>=xf
- xi=input('xi=');
- xf=input('xf=');
- end
- he=input('he=');
- while (he<0 || xi+he >=xf)
- he=input('he=');
- end
- xe=xi:he:xf;
- np=length(xe);
- if(xe(np)<xf)
- xe=[xe xf];
- np=np+1;
- end
- ye=FCE(xe);
- plot(xe,ye,'-r');
- xlabel('axa x');
- ylabel('axa y');
- Title('LABORATOR CN');
- grid;
- x0=input('xo=');
- x1=input('x1=');
- x2=input('x2=');
- f0=FCE(x0);
- f1=FCE(x1);
- f2=FCE(x2);
- iter=0;
- xr=x2;
- fr=f2;
- while (abs(fr)>EPS)
- iter=iter+1;
- if(x2>x0)
- t=x2;
- x2=x0;
- x0=t;
- t=f2;
- f2=f0;
- f0=t;
- end
- if (x0>x1)
- t=x0;
- x0=x1;
- x1=t;
- t=f0;
- f0=f1;
- f1=t;
- end
- if(x2>x1)
- t=x2;
- x2=x1;
- x1=t;
- t=f2;
- f2=f1;
- f1=t;
- end
- h1=x1-x0;
- if(abs(h1)<EPS)
- fprintf('h1-nul:algoritmul nu converge');
- return;
- end
- h2=x0-x2;
- r=h2/h1;
- d=r*(r+1)*(h1^2);
- if(abs(d)<EPS)
- fprintf('numitor nul pentru a');
- return;
- end
- a=(r*f1-f0*(1+r)+f2)/d;
- b=(f1-f0-a*(h1^2))/h1;
- c=f0;
- delta=b^2-4*a*c;
- if(delta<=0)
- fprintf('radacini complexe sau confundate');
- return;
- end
- if(b>=0)
- d=b+sqrt(delta);
- else
- d=b-sqrt(delta);
- end
- if(abs(d)<EPS)
- fprintf('numitor nul pentru xr');
- return;
- end
- xr=x0-(2*c)/d;
- fr=FCE(xr);
- if(xr>x0)
- x1=xr;
- f1=fr;
- else
- x2=xr;
- f2=fr;
- end
- fprintf('\niter=%g',iter);
- fprintf('\nxr=%g',xr);
- fprintf('\nfr=%g',fr);
- end
- fprintf('\nnumar total iteratii=%g',iter);
- fprintf('\nsolutie xr=%g',xr);
- fprintf('\nvaloare functie fr=%g',fr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement