CodeCodeCode

ENGR132: HW04 - fxy4C_name

Mar 30th, 2011
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.54 KB | None | 0 0
  1. function final = fxy4C_name(x, y)
  2.  
  3. %--------CALCULATIONS--------
  4. %If x and y are more than or equal to 0.
  5. if (x >= 0) && (y >= 0)
  6.     final = x^2 + y;
  7. end
  8. %If x is more than or equal to 0 and y is less than 0.
  9. if (x >= 0) && (y < 0)
  10.     final = x * y;
  11. end
  12. %If x is less than 0 and y is more than or equal to 0.
  13. if (x < 0) && (y >= 0)
  14.     final = x + y^2;
  15. end
  16. %If x and y are less than 0.
  17. if (x < 0) && (y < 0)
  18.     final = x^2 / y^2;
  19. end
  20.  
  21. %--------OUTPUTS--------
  22. %Prints out results.
  23. fprintf('f(%d,%d) = %0.2f', x, y, final)
Advertisement
Add Comment
Please, Sign In to add comment