Professional Documents
Culture Documents
Shrinathji Institute of Technology & Engineering, Nathdwara
Shrinathji Institute of Technology & Engineering, Nathdwara
Number of Experiment
SYSTEM PROGRAMMING LAB
DEPARTMENT OF ELECTRICAL Code: 5EE9A No.: 5
Pg No.1/7
EXPRIMENT NO.5
(A)What is a Script file? Explain & prepare a script file with an example.
A script file is a sequence of MATLAB commands, also called a program.
When a script file runs, MATLAB executes the commands in the order they are written
just as if they were typed in the Command Window.
When a script file has a command that generates an output, the output is displayed in the
Command Window.
Using a script file is convenient because it can be edited and executed many times.
Script files can be typed and edited in any text editor and then pasted into the MATLAB
editor.
Script files are also called M-files because the extension .m is used when they are saved
Case -1- The variable is defined and assigned value in the script file.
SHRINATHJI INSTITUTE OF TECHNOLOGY & ENGINEERING, NATHDWARA
Number of Experiment
SYSTEM PROGRAMMING LAB
DEPARTMENT OF ELECTRICAL Code: 5EE9A No.: 5
Pg No.2/7
Case-2- The variable is defined and assigned value in the Command Window
Case-3- The variables is defined in the script file, but a specific value is entered in the
command window when the script file is executed.
SHRINATHJI INSTITUTE OF TECHNOLOGY & ENGINEERING, NATHDWARA
Number of Experiment
SYSTEM PROGRAMMING LAB
DEPARTMENT OF ELECTRICAL Code: 5EE9A No.: 5
Pg No.3/7
OUTPUT COMMANDS
fprintf : display the output on the screen ,or to save output to a file
C o m m a n d w in d o w :
YEAR P O P U L AT IO N S
( M IL L IO N S )
1984 127
1986 130
1988 136
1990 145
1992 158
1994 178
1996 2 11
> > m r id u l7
e n te r th e p o in ts s c o r e d in th e fir s t g a m e 7 5
e n te r th e p o in ts s c o r e d in th e s e c o n d g a m e 6 0
e n te r th e p o in ts s c o r e d in th e th ir d g a m e 8 1
A n a v e ra g e of 7 2 .0 0 0 0 0 0 p o in ts w a s s c o r e d in th r e e g a m e s .> >
SHRINATHJI INSTITUTE OF TECHNOLOGY & ENGINEERING, NATHDWARA
Number of Experiment
SYSTEM PROGRAMMING LAB
DEPARTMENT OF ELECTRICAL Code: 5EE9A No.: 5
Pg No.5/7
Where
Req = ∑ is the equivalent resistance and Vs is the source voltage. The power
dissipated in each resistor is given by
Write a programme in script file that calculate the voltage source across each
resistor in a circuit that has resistor connected in series. When the script file is
executed user first enter the source voltage and then enter resistor of the
resistance in a vector.
SHRINATHJI INSTITUTE OF TECHNOLOGY & ENGINEERING, NATHDWARA
Number of Experiment
SYSTEM PROGRAMMING LAB
DEPARTMENT OF ELECTRICAL Code: 5EE9A No.: 5
Pg No.6/7
The programme displays a table with resistance in the first column, the
voltage across the resistor in the second and the power dissipated in the
resistor in the third column. The programme display the current in the circuit
and the total power.
R6 = 15Ω, R7 = 10Ω
Programme:-
%The program calculates the voltage across each resistor
Req=sum(Rn);
vn=Rn*vs/Req;
Pn=Rn*vs^2/Req^2;
i=vs/Req;
Ptotal=vs*i;
Table=[Rn',vn',Pn'];
disp('')
disp('')
disp(Table)
disp('')
[20 14 12 18 8 15 10]