Advertisement
FamiHug

SolveQuadratic_Octave_FAMILUG

Sep 22nd, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.48 KB | None | 0 0
  1. #by FamiHug
  2. #this script solve quadratic equation
  3.  
  4.  
  5. function [root1, root2] = solve_quadratic(a,b,c)
  6. delta = b*b - 4*a*c
  7. if (delta > 0)
  8.     root1 = (-b + sqrt(delta)) / (2*a)
  9.     root2 = (-b - sqrt(delta)) / (2*a)
  10. elseif (delta == 0)
  11.     root1 = (-b) / (2*a)
  12. else
  13.     disp("Phuong trinh vo nghiem");
  14. endif
  15. endfunction #Matlab ko co dong nay
  16.  
  17. solve_quadratic(1,5,6)#Không có ; ở cuối thì sẽ hiện ans
  18. disp(""); #in một dòng trắng
  19. solve_quadratic(1,5,6);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement