Advertisement
FamiHug

chiaDoi.m

Nov 18th, 2011
1,411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.82 KB | None | 0 0
  1. %By FamiHug@FAMILUG
  2. function [root1, root2] = chiadoi(f, saiso,cana,canb)
  3.  
  4. if subs(f,cana) * subs(f,canb) > 0
  5.  
  6.     disp('Khong co nghiem trong khoang a, b')
  7.  
  8. elseif subs(f,cana) * subs(f,canb) == 0
  9.  
  10.      disp('Mot trong 2 lai nghiem')
  11.  
  12.  else
  13.  
  14.       tb = mean(cana, canb);
  15.  
  16.       if subs(f,cana) * subs(f,tb) < 0
  17.  
  18.            if abs(tb - cana) < saiso
  19.  
  20.            else
  21.  
  22.                canb = tb;
  23.  
  24.            end
  25.  
  26.            
  27.  
  28.       elseif subs(f,cana) * subs(f,tb) > 0
  29.  
  30.           if abs(tb - canb) < saiso
  31.  
  32.           else
  33.  
  34.               cana = tb;
  35.  
  36.           end          
  37.  
  38.          
  39.  
  40.       else
  41.  
  42.           disp('mot trong 2 la nghiem')
  43.  
  44.       end
  45.  
  46.      
  47.  
  48.    
  49.  
  50.   end
  51.  
  52.   disp('ket qua')
  53.  
  54.   disp(cana)
  55.  
  56.  
  57.  
  58. end
  59.  
  60.  
  61.  
  62.  
  63.  
  64. function value = mean(a,b)
  65.  
  66.     value = (a+b)/2;
  67.  
  68.    
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement