CodeCodeCode

ENGR132: HW04 - Class3b_Activity5

Mar 30th, 2011
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.43 KB | None | 0 0
  1. function phase = Class3b_Activity5(temp, percent)
  2.  
  3. %--------CALCULATIONS--------
  4. % If percent composition is on interval [0,30)
  5. % (All possible values for "Solid A + comound AB" phase).
  6. if percent >= 0 && percent < 30
  7.     % Compares temperature "temp" to function y = (-65/30)x + 125.
  8.     % Depending on whether "temp" is more than, equal to, or less than y,
  9.     % we can find if it is above, on, or below our line.
  10.     if temp < ((percent * (-65 / 30)) + 125)
  11.         phase = 'Solid A + compound AB';
  12.     elseif temp == ((percent * (-65 / 30)) + 125)
  13.         phase = 'Between liquid and Solid B + compound AB';
  14.     elseif temp > ((percent * (-65 / 30)) + 125)
  15.         phase = 'Liquid';
  16.     end
  17. % If percent composition is 30.
  18. elseif percent == 30
  19.     % Checks values on point x = 30, which holds 3 possible phases as
  20.     % temperature "temp" increases from 0 to 150.
  21.     if temp >= 0 && temp < 60
  22.         phase = 'Between Solid A + compound AB and Solid B + compound AB';
  23.     elseif temp == 60
  24.         phase = 'Eutetic point';
  25.     elseif temp > 60 && temp <= 150
  26.         phase = 'Liquid';
  27.     end
  28. % If percent composition is on interval (30,100].
  29. elseif percent > 30 && percent <= 100
  30.     % Compares temperature "temp" to function y = (x - 30) + 60.
  31.     % Depending on whether "temp" is more than, equal to, or less than y,
  32.     % we can find if it is above, on, or below our line.
  33.     if temp < ((percent - 30) + 60)
  34.         phase = 'Solid B + compound AB';
  35.     elseif temp == ((percent - 30) + 60)
  36.         phase = 'Between liquid and Solid B + compound AB';
  37.     elseif temp > ((percent - 30) + 60)
  38.         phase = 'Liquid';
  39.     end
  40. end
  41. %--------OUTPUTS--------
  42. %Prints out given temperature, percent composition, and calculated phase.
  43. fprintf('Given temperature %d°C and percent composition %d%%, the phase is: %s.\n', temp, percent, phase);
  44.  
  45. % Class3b_Activity5(150,30);
  46. % Given temperature 150°C and percent composition 30%, the phase is: Liquid.
  47. % Class3b_Activity5(80,80);
  48. % Given temperature 80°C and percent composition 80%, the phase is: Solid B + compound AB.
  49. % Class3b_Activity5(90,60);
  50. % Given temperature 90°C and percent composition 60%, the phase is: Between liquid and Solid B + compound AB.
  51. % Class3b_Activity5(150,30);
  52. % Given temperature 150°C and percent composition 30%, the phase is: Liquid.
  53. % Class3b_Activity5(60,30);
  54. % Given temperature 60°C and percent composition 30%, the phase is: Eutetic point.
Advertisement
Add Comment
Please, Sign In to add comment