Advertisement
Guest User

wiokeee

a guest
May 29th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. clear;
  2. N = 10;
  3. disp(N,"N=");
  4. a = -2.0;
  5. disp(a,"a=");
  6. b=0.0;
  7. disp(b,"b=");
  8. h=0.001;
  9. function f=f(x);
  10. f=x*exp(x)-(x^2);
  11. endfunction;
  12. function fp=fp(x,h);
  13. fp=(f(x+h)-f(x))/h;
  14. endfunction;
  15. function fpp=fpp(x,h);
  16. fpp=(fp(x+h)-fp(x))/h;
  17. endfunction;
  18. function g=g(x);
  19. g=(f(x+f(x))-f(x))/f(x);
  20. endfunction;
  21. wi=0;
  22. if f(a)*f(b)<0 & fp(a)*fp(b)>0 & fpp(a)*fpp(b)>0 then
  23.  
  24. if f(a)*fpp(a)>0 then
  25. wi=wi+1;
  26. xp(wi)=a;
  27. disp(xp(wi));
  28. else
  29. wi=wi+1;
  30. xp(wi)=b;
  31. disp(xp(wi));
  32. end;
  33. for i=(wi+1):N
  34.  
  35. xp(i)=xp(i-1)-f(xp(i-1))/g(xp(i-1));
  36. disp(xp(i));
  37.  
  38. end;
  39. else
  40. disp("Założenia nie są spełnione");
  41. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement