Professional Documents
Culture Documents
Prepared by
Dr. Mohamed Saber Sokar
Dr. Mohamed Saber Sokar 2
Flow chart
Flow chart is a graphical
Flow Control
representation, illustrating the logical
steps, calculation and decisions, in
Using of M-File
sequence, that must be performed to
Writing practical m.files
accomplish a specific task.
Start
Enter
x1, x2, x3
Output
Stop y1, y2, y3
1
▌Flow chart -03 ▌Flow chart -04
3- Processing 4- If - Statement Syntax
Any constant value or equation must be indicated IF [condition]
in a rectangle [code to execute if condition is true]
ELSE
Constants constant = 9.81 [code to execute if condition is false]
END Dummy Example
a=2;
if (a<3)
Equations y =f(x) Some Matlab Commands;
else
Some Matlab Commands;
end
Dr. Mohamed Saber Sokar 7 Dr. Mohamed Saber Sokar 8
5.
2
▌Case study (flow chart) ▌Case study (*.m file)
Start % program to convert Fahrenheit temp. to Celsius
Enter F = input(' Enter Fahrenheit temperature: ');
Fahrenheit
c = 5/9* (F- 32);
Celsius = (Fahrenheit-32) disp( ' The Celsius temperature is: ' ), disp(c)
% or
Output
fprintf( ' The Celsius temperature is: %g \n ', c)
Celsius
Stop
Dr. Mohamed Saber Sokar 13 Dr. Mohamed Saber Sokar 14
8.314
for the molecular weight of a gas, mass,
temperature in Kelvin and volume to calculate
the pressure in S.I. units /
Output
Pressure (p)
Stop
3
▌Case study (*.m file) ▌pv diagram at T=c
% program to calculate gas pressure p-v diagram
800
m = input(' Enter mass of gas in [kg]= '); 700
Pressure [Pa]
T = input(' Enter temerature of gas in [K]= '); 500
R=8.314 / M; 400
300
V= 0 : 0.1 : Vmax; 200
p = m * R * T ./ V ; 100