In: Computer Science
(MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY) (MATLAB ONLY)
Please complete the following Question in MATLAB ASAP, Thanks. :)
2a. Write a function that outputs the amount of freezing point depression (in degrees C) given a mass of magnesium chloride salt and a volume of water. Formula to calculate freezing point depression: ΔT = iKm in which ΔT is the change in temperature in °C, i is the van't Hoff factor, which = 3 for MgCl2 because it dissociates into three ions, one Mg+2 and two Cl- , K is a constant that equals 1.86 °C kg/mol and m is the molality of the solute in mol/kg. Other useful information so you don’t have to look it up: Moles of MgCl2 = (mass MgCl2)/((atomic mass Mg)+2*(atomic mass Cl)) Atomic mass Mg = 24.31 Atomic mass Cl = 35.45 Assume the density of water is 1.0 g/mL
2b. Use your function to calculate the depression for 100g MgCl2 dissolved in 500mL water
2c. Use your function to calculate the depression for 220g MgCl2 dissolved in 1L water
2d. Make a plot that shows the mass of MgCl2 necessary to depress the freezing point of a given volume (range: 1L - 100L) water by 1 degree Celsius. Give your plot appropriate labels and a title.
Matlab code:
clc
clear all
% part 2a : function definition is at the end of the code. please scroll
% down
% part 2b
mass_salt = 100; % mass of MgCl2 in g
vol_water= 500; % vol of water in ml
delta_T = depression(mass_salt,vol_water);
X1 =['Part 2b : depression in freezing point when ',num2str(mass_salt),...
' g MgCl2 is dissolved in ',num2str(vol_water),' ml water is ',...
num2str(delta_T),' degree celcius'];
disp(X1);
% part 2c
mass_salt = 220; % mass of MgCl2 in g
vol_water= 1000; % vol of water in ml
delta_T = depression(mass_salt,vol_water);
X2 =['Part 2c : depression in freezing point when ',num2str(mass_salt),...
' g MgCl2 is dissolved in ',num2str(vol_water),' ml water is ',...
num2str(delta_T),' degree celcius'];
disp(X2);
% part 2d
delta_T= 1; % value given in C
i=3; % value given
K=1.86; % value given in C kg/mol
vol_water_L =1:1:100; % Volume range from 1 to 100 L
density_water =1; % water density in g/ml or kg/L
mass_water_kg = vol_water_L*density_water; % mass unit becomes kg
mol_salt = delta_T*mass_water_kg/i/K; % from rearranging formula
mol_wt_salt= 24.31+35.45+35.45; % mass of 1 Mg and 2 Cl in g/mol
mass_salt_g=mol_salt*mol_wt_salt;
plot(vol_water_L,mass_salt_g); % plotting required graph
xlabel('vol of water in L');
ylabel(' mass of MgCl2 in g');
title('mass of MgCl2 salt required to depress freezing point by 1 degree celcius in water');
% part 2a : defining function to calculate depression in freezing point
function [delta_T]= depression(mass_salt,vol_water)
i=3; % van't hoff factor
K=1.86; % depression constant
mol_wt_salt= 24.31+35.45+35.45; % mass of 1 Mg and 2 Cl in g/mol
mol_of_salt=mass_salt/mol_wt_salt;
density_water = 1; % g/ml
mass_water_kg= vol_water*density_water/1000; % mass in kg
molality=mol_of_salt/mass_water_kg;
delta_T=i*K*molality;
end