T0=273.15; L=2.48*10^6; Rv=461.5; e0=6.11; e=zeros(46,1); A=17.27; %Defining the constants and variables. T1=36; e1=zeros(46,1); e2=zeros(46,1); C=zeros(46,1); x=zeros (46,2); %Defining the constants and variables. y=zeros (46,2); z=zeros (46,2); L0=2500.3*10^3; alpha = -1.9449; %Defining the constants and variables. %The values of L0 and alpha were obtained in question 5. S = load('vapour_pressure.dat'); %Loading data from file vapour_pressure.dat and writing them to matrix S. % for ii = 1:46 %Initiates a loop in order to perform calculations on 46 values of e and temperature. e(ii)=e0*exp(-(L/Rv)*((1/S(ii,2))-(1/T0))); %Performs the calculations according to theoretical formula (1). e1(ii)=e0*exp((A*(S(ii,2)-T0))/(S(ii,2)-T1)); %Performs the calculations according to empirical formula (2). e2(ii)=((S(ii,2)/T0)^(alpha/Rv))*e0*exp(-(L0/Rv)*((1/S(ii,2))-(1/T0))); %Does calc. according to final formula. C(ii) = S(ii,2) - 273.15; %This calculates the values of temperature in Celsius and writes them to C. end %Ends the loop. y(:,1) = C; %Assigns values of temperature to matrix y. y(:,2) = e; %Assigns values of SVP from eq.1 to matrix y. x(:,1) = C; %Assigns values of temperature to matrix x. x(:,2) = e1; %Assigns values of SVP from eq.2 to matrix x. z(:,1) = C; %Assigns values of temperature to matrix z. z(:,2) = 10*S(:,1); %Assigns values of measured SVP to matrix z. fid = fopen('results.txt', 'wt'); %Creates and opens (or only opens) the file results.txt in write mode. fprintf(fid,'%12s %28s\n','Temperature','SVP calc. (theor. formula)'); %Prints the headers into the file. fprintf(fid,'%12s %12s\n','(degrees C)','(hPa)'); %Prints the headers into the file. fprintf(fid,'%5.0f %20.4f\n', transpose (y)); %Prints the numerical values into the file. fprintf(fid,'%12s %12s\n','',''); %Adds a gap between the sets of data for better legibility. fprintf(fid,'%12s %28s\n','Temperature','SVP calc. (empir. formula)'); %Prints the headers into the file. fprintf(fid,'%12s %12s\n','(degrees C)','(hPa)'); %Prints the headers into the file. fprintf(fid,'%5.0f %20.4f\n', transpose (x)); %Prints the numerical values into the file. fprintf(fid,'%12s %12s\n','',''); %Adds a gap between the sets of data for better legibility. fprintf(fid,'%12s %15s\n','Temperature','SVP measured'); %Prints the headers into the file. fprintf(fid,'%12s %12s\n','(degrees C)','(hPa)'); %Prints the headers into the file. fprintf(fid,'%5.0f %18.2f\n', transpose (z)); %Prints the numerical values into the file. fclose(fid); %Closes the file after all the data has been printed to it. subplot (111), plot (C, e, C, e1, C, 10*S(:,1)); %Plots the three curves on a single graph. title ('Graph showing how the SVP varies with temperature'); %Adds title to the graph. xlabel ('Temperature (Degrees Celsius)'); %Adds a label to the x-axis. ylabel ('SVP (hPa)'); %Adds a label to the y-axis. legend ('Blue: SVP calculated by the theoretical formula','Green: SVP calculated by the empirical formula','Red: SVP measured','Location','Northwest'); print -djpeg 1GraphOfAllThreeMeasurements %Saves the current graph in a JPEG file. subplot (121), plot(C,e,'b',C,10*S(:,1),'r');%Plots a graph of theoretical and measured SVP to the left half. title ('Graph to show how theoretical formula describes SVP vs. T'); %Adds title to the graph. xlabel ('Temperature (Degrees Celsius)'); %Adds a label to the x-axis. ylabel ('SVP (hPa)'); %Adds a label to the y-axis. axis([-5 40 4 76]); %Sets the range of the axes. legend ('Blue: Theoretical formula','Red: Measured','Location','Northwest'); %Adds a legend to the top left. subplot (122), plot(C,e1,'g',C,10*S(:,1),'r');%Plots a graph of empirical and measured SVP to the right half. title ('Graph to show how empirical formula describes SVP vs. T'); %Adds title to the graph. xlabel ('Temperature (Degrees Celsius)'); %Adds a label to the x-axis. ylabel ('SVP (hPa)'); %Adds a label to the y-axis. axis([-5 40 4 76]); %Sets the range of the axes. legend ('Green: Empirical formula','Red: Measured','Location','Northwest'); %Adds a legend to the top left. print -djpeg 2GraphsToCompareCalculationsWithMeasurements %Saves the current graph in a JPEG file. R = load('LatentHeatVsTemperature.txt'); %Loads the Temperature and Latent Heat data obtained from DataSheet. M = R(:,1); %Loads the first column of R into matrix M. N = R(:,2); subplot (111), plot (M,N,'x'); title ('Graph showing how latent heat varies with temperature'); %Adds title to the graph. xlabel ('Temperature (Degrees Celsius)'); %Adds a label to the x-axis. ylabel ('Latent Heat of vaporisation of water (J/g)'); %Adds a label to the y-axis. axis([-5 57 2390 2520]); %Sets the range of the axes. subplot (121), plot(C,e1,'b',C,10*S(:,1),'r'); title ('Graph to show how the empirical formula describes SVP vs. T'); %Adds title to the graph. xlabel ('Temperature (Degrees Celsius)'); %Adds a label to the x-axis. ylabel ('SVP (hPa)'); %Adds a label to the y-axis. axis([-5 40 4 76]); %Sets the range of the axes. legend ('Blue: Empirical formula','Red: Measured','Location','Northwest'); %Adds a legend to the top left. subplot (122), plot(C,e2,'g',C,10*S(:,1),'r'); title ('Graph to show how the "new" formula describes SVP vs. T'); %Adds title to the graph. xlabel ('Temperature (Degrees Celsius)'); %Adds a label to the x-axis. ylabel ('SVP (hPa)'); %Adds a label to the y-axis. axis([-5 40 4 76]); %Sets the range of the axes. legend ('Green: New formula','Red: Measured','Location','Northwest'); %Adds a legend to the top left. print -djpeg 3FinalGraph %Saves the current graph in a JPEG file. % The error has been identified to be the measurement % of 62.62hPa at 38 degrees Celsius. This error has been corrected by the % use of the cubic equation of the fitted line (Vapourpressure = 1.2377z^3+ % + 6.5741z^2 + 17.011z + 19.925), where z = (c - 17.5)/13.423 % C is the temperature in degrees Celsius. The corrected value of % that vapour pressure is 65.65.