0% found this document useful (0 votes)
33 views13 pages

PPE-309L Process Lab: Engineering Computing

The document describes a lab assignment on conditional statements and using MATLAB. It includes instructions on writing scripts to return the absolute value and square root of a number depending on its sign, as well as practice exercises on if and if-else statements. It also provides a tutorial question to estimate the molecular weight of an oil fraction using given properties and plot molecular weight versus boiling temperature for different API gravities.

Uploaded by

Ali Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views13 pages

PPE-309L Process Lab: Engineering Computing

The document describes a lab assignment on conditional statements and using MATLAB. It includes instructions on writing scripts to return the absolute value and square root of a number depending on its sign, as well as practice exercises on if and if-else statements. It also provides a tutorial question to estimate the molecular weight of an oil fraction using given properties and plot molecular weight versus boiling temperature for different API gravities.

Uploaded by

Ali Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PPE-309L Process

Engineering Computing
Lab
2020 Fall-5th Semester
Instructor: Ms. Komal Naveed
Email id: [email protected]
Designation: Graduate assistant
University of Engineering and Technology Lahore
Conditional statements
Solution with MATLAB
 Create an M-file
 Save the file with the name of abs_num
 Write the following script
 %%%%prompt the user for a number and print its absolute
 num=input('please enter a number:');
Writing a script  %%%if the user entered the negative number, change it
to return the  if num > 0
 number=num
absolute value  end
of a number  if num < 0
 disp('ok,the number is negative, we will use the absolute
number')
 number = abs(num)
 end
 To run the script abs_num, type abs_num in the
command window and press enter
 You will be asked to enter your number
Writing a script
to return the
absolute value
of a number

 Type ‘-4’. Matlab returns the absolute value ‘4’


 %%%%prompt the user for a number and print its sqrt
 num=input('please enter a number:');
 %%%if the user entered the positive number, find the square root
 if num > 0
Writing a script  number=sqrt(num);
to return the  end

absolute value 
%%%if the user entered the negative number, change it
if num < 0
of a number  number1 = abs(num)
 number = sqrt(number1);
 end
 disp('OK, we''ll use the absolute value')
 fprintf('the sqrt of %.1f is %.1f\n',num,number)
 Write an if statement that would print “No overtime for
Practice you” if the value of a variable hours is less than 40. “A
10% increment will be given to those who have worked
exercise- for 40-50 hours and 30% for those who have worked for
conditional 50 hours. Test the if statement for values of hours both
less than and greater than 40.
statement
age=input(‘Please enter your age:');
if age < 15
disp('you are not eligible for driving license')
The if-else elseif age < 20
statements- disp('you may eligible for driving license after a trial')
example else
disp ('you are eligible for driving license')
end
 Write an if-else statement that would calculate the
Practice area of a circle only if the value of a variable radius is
exercise-if-else greater than zero. Use fprintf function to return the
value of area.
statement
 In petroleum industries, it is common that the molecular weight of
an oil fraction is unknown and thus must be estimated by using a
correlation. A correlation that is widely used is developed by Riazi
and Daubert, which is also referred to as the API (American
Tutorial #1 Petroleum Institute) method. The correlation can be applied to
hydrocarbons with molecular weight ranging from 70-700, which is
Question#1 nearly equivalent to boiling point range of 300-850 K, and the API
gravity range of 14.4-93. This molecular weight (M) correlation is
given as a function of the average boiling point (Tb) and the
specific gravity at 60°F (SG) of the oil fraction of interest as
follows:
Where, Tb is in K and SG is related to the API gravity (API):

Tutorial #1
Question#1
 Estimate the molecular weight of an oil fraction that has an
average boiling point of 344.7°C and an API gravity of 50.
 Plot a graph M vs.T (400 < Tb< 600 K) with API gravity = 20, 40,
and 60.
Part a)
 TB=344.7+273 %Boiling Temperature in kelvin

M-file  API=50; %%Given API values


 SG=141.5/(API+131.5)
commands
 M=42.965*exp(2.097e-4*(TB)-(7.78712*SG)+(2.08476e-
Part (a) 3*(TB)*SG))*(TB^1.26007)*(SG^4.98308);
 fprintf('\n molecular weight of oil fraction:%.2f\n', M)
 Tb=400:600; %Boiling Temperature range in kelvin
 API=20:20:60 % Given API values
 SG=141.5./(API+131.5) %SG values for given APIo values
 %Molecular Weight Calculations
 M1=42.965*exp(2.097e-4.*(Tb)-7.78712.*SG(1)+2.08476e-
3.*(Tb.*SG(1))).*Tb.^1.26007.*SG(1)^4.98308; %Molecular Weight for SGo(1)in
g/gmole
 M2=42.965*exp(2.097e-4.*(Tb)-7.78712.*SG(2)+2.08476e-
3.*(Tb.*SG(2))).*Tb.^1.26007.*SG(2)^4.98308; %Molecular Weight for SGo(2)in
g/gmole
Part (b)  M3=42.965*exp(2.097e-4.*(Tb)-7.78712.*SG(3)+2.08476e-
3.*(Tb.*SG(3))).*Tb.^1.26007.*SG(3)^4.98308; %Molecular Weight for SGo(3)in
g/gmole
 plot(M1,Tb,'x--',M2,Tb,'o--',M3,Tb,'s:')
 title('Molecular weight VS Boiling Temperatures')
 xlabel('Molecular Weight (g/gmole)')
 ylabel('Boiling Temperatures (Kelvin)')
 legend('API=20','API=40','API=60')
Graph-Part (b)

You might also like