Facebook
From ASDASD, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 257
  1. y=0;
  2. stop=1;
  3. eps=0.001;
  4.  
  5. x=[-5:0.001:5];        %przedziaƂ
  6.  
  7. y=8+x.*2+x.^2+4*x.^3;  
  8. plot(x,y,'-r'); hold on;
  9.  
  10. x1=-5;
  11. x2=5;
  12. i=0;
  13.  
  14. while(stop==1)
  15.     i=i+1;
  16.     x0=(x1+x2)/2;
  17.     y0=8+x0*2+x0^2+4*x0^3;
  18.     y1=8+x1*2+x1^2+4*x1^3;
  19.    
  20.         if((y1*y0)<0)
  21.             x2=x0;
  22.         else
  23.             x1=x0;
  24.         end
  25.     plot(x0,y0,'ys');
  26.     delta=(x2-x1)/x2;
  27.     wzgl=abs(delta);
  28.         if(wzgl<eps)
  29.             stop=0;
  30.         else
  31.             stop=1;
  32.         end
  33.        
  34.    
  35. end
  36. fprintf('Miejsce zerowe funkcji to: %d', x0, s);
  37.  
  38.