function MaterialProperties(Material,HeatofFusion, TempofFusion, SpecificHeat, DensityMatrix, MinEnergyRequirement, MaxEnergyRequirement, LowestTemp, Costperkg)
% AUTHOR: Courtney Hiatt
% DATE: 3/26/2024
% INPUTS: Material Properties and Energy Requirements
% OUTPUTS: Graphs and Tables regarding mass and volume requirements

% This MATLAB code inputs the material properties and minimum to maximum
% energy requirements and outputs data and graphs on the required mass,
% volume, and price required to run the AC through the night. 


%Initializing values
RoomTemp = 20; %C
dT = RoomTemp-LowestTemp; %C
T = linspace(LowestTemp,RoomTemp,20)'; %C
density = interp1(DensityMatrix(1,:),DensityMatrix(2,:),T); %kg/m^3
MinDensity = min(density); %kg/m^3
EnergyValues = linspace(MinEnergyRequirement, MaxEnergyRequirement, 20)'; %kJ
Mass = EnergyValues./(SpecificHeat*dT+HeatofFusion); %kg
Volume = Mass/MinDensity;
Latent = Mass*HeatofFusion;
Sensible = EnergyValues-Latent;
Cost = Mass*Costperkg;

% If the material does not go through phase change, the latent heat is 0,
% and this can be accounted for by changing the heat of fusion to 0. 
if (LowestTemp > TempofFusion) || (TempofFusion > RoomTemp)
    HeatofFusion = 0;
end

%Plotting and creating a table of the mass and volume required for the
%minimum to maximum energy requirements
A = [EnergyValues, Mass, Volume, Latent, Sensible];
Table1 = array2table(A, 'VariableNames', {'Energy Requirmenets (kJ)', 'Mass Required (kg)', 'Volume Required (m^3)', 'Latent Heat Storage (kJ)', 'Sensible Heat Storage (kJ)'});
text = 'Mass and Volume Requirements for Energy Requirements ';
txt = append(text,Material);
Table1 = table(Table1, 'VariableNames', {txt})

figure
hold on
text = 'Mass and Volume Material Required for ';
txt = append(text,Material);
title(txt)
xlabel('Energy Required (kJ)')
yyaxis left
plot(EnergyValues,Mass)
ylabel('Mass of Material Required (kg)')
yyaxis right
plot(EnergyValues,Volume)
ylabel('Max volume of material requied (m^3)')
hold off

figure
hold on
text = 'Price and Mass Material Required for ';
txt = append(text,Material);
title(txt)
xlabel('Energy Required (kJ)')
yyaxis left
plot(EnergyValues,Mass)
ylabel('Mass of Material Required (kg)')
yyaxis right
plot(EnergyValues,Cost)
ylabel('Cost ($)')
hold off

%This creates a table and plot of the changes in volume for the max and min energy
%requirement
MaxMass = MaxEnergyRequirement./(SpecificHeat*dT+HeatofFusion); %kg
MaxVolumes = MaxMass./density; %m^3
MinMass = MinEnergyRequirement./(SpecificHeat*dT+HeatofFusion); %kg
MinVolumes = MinMass./density; %m^3

B = [T, MaxVolumes];
Table2 = array2table(B, 'VariableNames', {'Temperature (C)', 'Volume'});
text = 'Volume Requirements for Maximum Energy Requirements ';
txt = append(text,Material);
Table2 = table(Table2, 'VariableNames', {txt})
C = [T, MinVolumes];
Table3 = array2table(C, 'VariableNames', {'Temperature (C)', 'Volume (m^3)'});
text = 'Volume Requirements for Minimum Energy Requirements ';
txt = append(text,Material);
Table3 = table(Table3, 'VariableNames', {txt})

figure
hold on
plot(T,MaxVolumes)
plot(T,MinVolumes)
xlabel('Temperature (C)')
ylabel('Volume (m^3)')
text = 'Volume Requirements at Varying Temperatures for ';
txt = append(text,Material);
title(txt)
legend('Max Energy Requirements', 'Min Energy Requirements')
hold off

end