Advertisement
cybereq

zad3

Oct 25th, 2023
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.63 KB | None | 0 0
  1.      
  2. %%
  3. i=100;
  4. a=-1;
  5. b=2;
  6. x=linspace(a,b,i);
  7.  
  8. h=0.2;
  9. x0=0.3;
  10. e=10^(-3);
  11.  
  12. x1=x0-(funkcja1(x0,h))/(funkcja2(x0,h));
  13. x2=x1;
  14.  
  15. for j=1:i
  16.     x3=x2-(funkcja1(x2,h)/funkcja2(x2,h));
  17.     if abs(x3-x2)<=e
  18.         break;
  19.     else
  20.         x2=x3;
  21.     end
  22. end
  23.  
  24.  
  25. figure(3);
  26. plot(x,funkcja(x));hold on;
  27. plot(x0,funkcja(x3),'X');
  28.  
  29.        
  30. function [funkcja] = funkcja(x)
  31. funkcja=-(1./((x-0.3).^2+0.01))-(1./(((x-0.9).^2)+0.04))+6;
  32. end
  33.  
  34. function [funkcja1] = funkcja1(x,h)
  35. funkcja1=(funkcja(x+h)-funkcja(x-h))/(2*h);
  36. end
  37.  
  38. function [funkcja2] = funkcja2(x,h)
  39. funkcja2=(funkcja(x+h)-2*funkcja(x)+funkcja(x-h))/(h^2);
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement