Advertisement
anhhoang2703

Untitled

Oct 16th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. clc; clear all; close all;
  2. syms x k;
  3. fc=0;
  4. c=0;
  5. y=x+cos(x);
  6. yx=vectorize(y)
  7. del=1e-9
  8. vectorize(y);
  9. a=-5
  10. b=5
  11. while 1
  12. fa=double(subs(y,'x',a))
  13. fb=double(subs(y,'x',b))
  14. c=(a+b)/2;
  15. fc=double(subs(y,'x',c))
  16. k=k+1
  17. if fa*fc>0
  18. a=c;
  19. else if fa*fc<0
  20. b=c;
  21.  
  22. end
  23. end
  24. if(abs(fc)<=1e-9)
  25. break;
  26. end
  27. end
  28. fprintf('Nghiem x = %12.10f \n',c);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement