CodeCodeCode

ENGR132: HW04 - fxy4F_name

May 1st, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.72 KB | None | 0 0
  1. function final = fxy4F_name(x, y)
  2.  
  3. % FUNCTION: Calculates "final" based on given numbers "x" and "y".
  4. %
  5. % INPUTS:
  6. % 1) x: The x input.
  7. % 2) y: The y input.
  8. %  
  9. % OUTPUTS:
  10. % 1) final: The final product of the calculation.
  11.  
  12. %--------CALCULATIONS--------
  13. %If x and y are more than or equal to 0.
  14. if (x >= 0) && (y >= 0)
  15.     final = x^2 + y;
  16. %If x is more than or equal to 0 and y is less than 0.
  17. elseif (x >= 0) && (y < 0)
  18.     final = x * y;
  19. %If x is less than 0 and y is more than or equal to 0.
  20. elseif (x < 0) && (y >= 0)
  21.     final = x + y^2;
  22. %If x and y are less than 0.
  23. elseif (x < 0) && (y < 0)
  24.     final = x^2 / y^2;
  25. end
  26.  
  27. %--------OUTPUTS--------
  28. %Prints out results.
  29. fprintf('f(%d,%d) = %0.2f', x, y, final)
Advertisement
Add Comment
Please, Sign In to add comment