All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
close all clear all clc %Opening the file that is stored in the file Thermo = fopen('THERMO.dat','r') %Getting the first line from the opened file fgetl(Thermo); f1 = fgetl(Thermo); A = strsplit(f1, ' '); Global_low_temperature = str2num(A{2}); Global_mid_temperature = str2num(A{3}); Global_high_temperature = str2num(A{4});…
Aatas A G
updated on 11 Nov 2021
close all
clear all
clc
%Opening the file that is stored in the file
Thermo = fopen('THERMO.dat','r')
%Getting the first line from the opened file
fgetl(Thermo);
f1 = fgetl(Thermo);
A = strsplit(f1, ' ');
Global_low_temperature = str2num(A{2});
Global_mid_temperature = str2num(A{3});
Global_high_temperature = str2num(A{4});
fgetl(Thermo);
fgetl(Thermo);
fgetl(Thermo);
for i = 1:53
f2 = fgetl(Thermo);
B = strsplit(f2, ' ');
Species_name = (B{1});
Local_low_temperature = str2num(B{end-3});
Local_high_temperature = str2num(B{end-2});
Local_mid_temperature = str2num(B{end-1});
f3 = fgetl(Thermo);
C = findstr(f3, 'E');
Coeff1 = f3(1:12+3);
Coeff2 = f3(16:30);
Coeff3 = f3(31:45);
Coeff4 = f3(46:60);
Coeff5 = f3(61:75);
f4 = fgetl(Thermo);
D = findstr(f4,'E');
Coeff6 = f4(1:15);
Coeff7 = f4(16:30);
Coeff8 = f4(31:45);
Coeff9 = f4(46:60);
Coeff10 = f4(61:75);
f5 = fgetl(Thermo);
E = findstr(f5,'E');
Coeff11 = f5(1:15);
Coeff12 = f5(16:30);
Coeff13 = f5(31:45);
Coeff14 = f5(46:60);
%To calculate the various Thermodynamic Properties:
T = [Local_low_temperature : Local_high_temperature];
j=1;
Specific_Heat = 0;
Enthalpy = 0;
Entropy = 0;
%High_temp_coeffs = Coeff1, Coeff2, Coeff3, Coeff4, Coeff5, Coeff6, Coeff7
%Low_temp_coeffs = Coeff8, Coeff9, Coeff10, Coeff11, Coeff12, Coeff13, Coeff14
for t = T
R = 8.314; %Universal Gas Constant
if t <= Local_mid_temperature
a1= str2num(Coeff8);
a2= str2num(Coeff9);
a3= str2num(Coeff10);
a4= str2num(Coeff11);
a5= str2num(Coeff12);
a6= str2num(Coeff13);
a7= str2num(Coeff14);
else
a1= str2num(Coeff1);
a2= str2num(Coeff2);
a3= str2num(Coeff3);
a4= str2num(Coeff4);
a5= str2num(Coeff5);
a6= str2num(Coeff6);
a7= str2num(Coeff7);
end
%Thermodynamic Property Formulae:
Specific_Heat(j) = (a1 + (a2* t) + (a3* t^2) + (a4* t^3) + (a5* t^4))* R;
Enthalpy(j) = (a1 + (a2 * t) / 2 + (a3 * t^2) / 3 + (a4 *t^3) / 4 + (a5* t^4) / 5 + (a6 / t)) * R * t;
Entropy(j) = (a1 * log(t) + (a2 * t) + (a3 * t^2) / 2 + (a4 * t^3) / 3 + (a5 * t^4) / 4 + (a7)) * R;
j = j+1;
end
%Plotting the results:
plot(T, Specific_Heat, 'linewidth', 3, 'color', 'r')
xlabel('Temperature (K)')
ylabel('Specific Heat (J kg−1 K−1)')
title(char(Species_name))
url = sprintf('E:/MHEV/Project/%s/Specific Heat Plot.jpg',Species_name);
saveas(gcf,url)
plot (T, Enthalpy, 'linewidth', 3, 'color', 'b' )
xlabel('Temperature (K)')
ylabel('Enthalpy (J)')
title(char(Species_name))
url1 = sprintf('E:/MHEV/Project/%s/Enthalpy Plot.jpg',Species_name);
saveas(gcf,url1)
plot(T, Entropy, 'Linewidth', 3, 'color', 'g')
xlabel('Temperature (K)')
ylabel('Entropy (J/K)')
title(char(Species_name))
url2 = sprintf('E:/MHEV/Project/%s/Entropy Plot.jpg',Species_name);
saveas(gcf,url2)
%To calculate the Molecular weight of the Species:
Q = 0;
%All the atoms that are used in all the Species are mentioned here.
Atoms = ['H', 'C', 'N', 'O', 'A', 'R', '(', ')', 'S'];
%Corresponding Atomic masses are stated here
Atomic_mass = [1, 12, 14, 16, 40, 0, 0, 0, 0];
for k= 1:length(Species_name)
z = Species_name(k) == Atoms; %Creating a Logical Array under the variable of z.
ind = find(z==1); %Finding the index where we can get
z = z*z'; %z' = Z_transpose
if z
Q(k) = Atomic_mass(ind); %We take the Atomic Mass at the index where we get a 1 in the logical array.
else
Atomic_mass_index = find(Atoms==Species_name(k-1));
Q(k-1) = str2num(Species_name(k)) * Atomic_mass(Atomic_mass_index);
end
end
Molecular_weight(i) = sum(Q);
%Species_Name = Species_name(i)
fprintf('Molecular Weight of %s = %f u', Species_name, Molecular_weight(i))
end
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 4 - CHT Analysis on Exhaust port
AIM: To perform the simulation of Conjugate heat transfer analysis on given exhaust port geometry by using ANSYS FLUENT. OBJECTIVE: To study the importance of Conjugate heat transfer analysis and importance of y+ value during meshing of the components. To perform the simulation of Conjugate heat transfer analysis on given…
12 Dec 2022 08:19 AM IST
Week 10 - Simulating Combustion of Natural Gas.
AIM To perform a combustion simulation on the combustor model. Objective Part I Perform a combustion simulation on the combustor model and plot the variation of the mass fraction of the different species’ in the simulation using line probes at different locations of the combustor as shown in Fig. You need to plot…
07 Dec 2022 11:26 AM IST
Week 9 - Parametric study on Gate valve.
Aim: To perform a parametric study on Gate valve. Objective: Simulate the flow of fluid through a gate valve. Perform the parametric study on the gate valve by setting design points corresponding to the positions of the lift of the spindle. Calculate the mass flow rate corresponding to all the design points Gate…
07 Dec 2022 10:12 AM IST
Project 2
AIM: To deal with the development of a forward energy-based fuel consumption model of a P1 hybrid vehicle. OBJECTIVE: Load the Project2 folder as the Current Folder in Matlab. Run the “Project2_InitFile.m” Matlab script. Copy the Conventional vehicle Simulink model created for Project 1 in this folder. Figure…
25 Oct 2022 01:11 PM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.