5. Script M file

A script file is an external file that contains a sequence of MATLAB statements. By typing the filename, subsequent MATLAB input is obtained from the file.

% frictionfactor.m
% Done on 16-Dec-2001
% Re-Done on 28-Jan-2011
D = input('Dia in meter = ');
v = input('Velocity in m/s = ');
rho = 1000; % Density of water in kg/m3
mu = 0.001; % Viscosity of water in kg/m.s

Re = D*v*rho/mu
f = 0.079*Re^(-0.25);
disp(f);
This script file saved as frictionfactor.m shall be called from the command prompt as follows. The code therein will be executed.
>> frictionfactor 
Dia in meter = .1
Velocity in m/s = 2
Re =
      200000
    0.0037
The input command is to input the data from the user during the run time. The disp is to display the value of a variable in the command window.