Jim421616

Modelling Assignment Function

Sep 29th, 2021 (edited)
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.60 KB | None | 0 0
  1. function [solns] = ModellingAssignment1BFuns(t, T1, T2, C1, C2)
  2.  
  3. % time (s) is independent variable
  4. %Definition of global variables
  5. global t
  6. global M1 % Mass in tank 1 kg
  7. global M2 % Mass in tank 2 kg
  8. global cp % Specific heat capacity of reactant J.kg-1 °C-1
  9. global T1 % Temperature in tank 1 °C
  10. global T2 % Temperature in tank 2 °C
  11. global THi % Temperature of jacket fluid in °C
  12. global THo % Temperature of jacket fluid out °C
  13. global THm % Temperature of jacket between tank 1 and 2 °C
  14. global E % Activation energy J.mol-1
  15. global R % Ideal gas constant J.mol-1K-1
  16. global k % Rate constant at (mol.kg-1)1-n s-1
  17. global T1i % Initial temperature in tank 1 °C
  18. global T2i % Initial temperature in tank 2 °C
  19. global F % Flowrate between tanks kg.s-1
  20. global q % Flowrate of heating fluid in jackets kg.s-1
  21. global cpw % Specific heat capacity of heating fluid J.kg-1 °C-1
  22. global C1 % Concentration in tank 1 mol.kg-1
  23. global C2 % Concentration in tank 2 mol.kg-1
  24. global Cf % Feed concentration to tank 1 mol.kg-1
  25. global UA % Overall htc jacket to tanks W.m-2°C-1
  26. global C1i % Initial concentration in tank 1 mol.kg-1
  27. global C2i % Initial concentration in tank 2 mol.kg-1
  28.  
  29. % Make sure the time arrays used in the ode solver is the same interval and
  30. % length as in the experimental data
  31.  
  32. % Define an array to hold the solutions
  33. [solns] = zeros(1, 5); % 1 row, 4 cols (time, temp1/temp2, conc1/conc2)
  34. solns(1) = t;
  35. % These are the ODEs that model the system
  36. % 𝑀1𝑐𝑝*𝑑𝜃/𝑑𝑡 = 𝐹𝑐_𝑝(𝜃𝐹 − 𝜃1) + 𝑈1𝐴1∆𝜃𝑙𝑚1 𝑓𝑜𝑟 𝑡 > 0
  37. % 𝑀2𝑐𝑝*𝑑𝜃/𝑑𝑡 = 𝐹𝑐𝑝(𝜃1 − 𝜃2) + 𝑈2𝐴2∆𝜃𝑙𝑚2 𝑓𝑜𝑟 𝑡 > 0
  38. % 𝑀1𝑑𝐶1/𝑑𝑡 = 𝐹(𝐶𝐹 − 𝐶1) − 𝑘1𝐶𝑀1 𝑓𝑜𝑟 𝑡 > 0
  39. % 𝑀2𝑑𝐶2/𝑑𝑡 = 𝐹(𝐶1 − 𝐶2) − 𝑘2𝐶𝑀2 𝑓𝑜𝑟 𝑡 > 0
  40.  
  41. % Algebraic equations
  42. % Arrhenius law
  43. ko = 10;
  44. k = ko*exp(-E/(R *(T1 + 273.15)));
  45. % Calculate THo and THm
  46. THo = T1 + (THm - T1)*exp(-UA/F/cpw);
  47. THm = T2 + (THi - T2)*exp(-UA/F/cpw);
  48.  
  49. % Calculate log mean temp differences
  50. lm1 = (THm - THo)/log((THm - T1)/(THo - T1));
  51. lm2 = (THi - THm)/log((THi - T2)/(THm - T2));
  52.  
  53. % ODEs
  54. % Calculate temperature for tank 1
  55. dT1_dt = (F*cp*(T - T1i) + UA*lm1)/ (M1*cpw);
  56. solns(2) = dT1_dt;
  57. % Calculate temperature for tank 2
  58. dT2_dt = (F*cp*(Tf - T2i) + UA*lm2)/ (M2*cpw);
  59. solns(3) = dT2_dt;
  60.  
  61. % Calculate concentration in tank 1
  62. dC1_dt = (F(Cf - C1) - k*C1*M1) / M1;
  63. solns(4) = dC1_dt;
  64. % Calculate concentration in tank 2
  65. dC2_dt = (F(C1 - C2) - k*C2*M2) / M2;
  66. solns(5) = dC2_dt;
  67.  
  68.  
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment