Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

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

Input to a Script File

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

 disp : displays the output on the screen

disp(name of a variable) or disp(‘text as string’).

 fprintf : display the output on the screen ,or to save output to a file

fprintf(‘text typed in as a string’)


SHRINATHJI INSTITUTE OF TECHNOLOGY & ENGINEERING, NATHDWARA
Number of Experiment
SYSTEM PROGRAMMING LAB
DEPARTMENT OF ELECTRICAL Code: 5EE9A No.: 5
Pg No.4/7

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

(B) When several resistors are connected in an electrical network in series,


the voltage across each of them is given by the voltage divider rule

Where

Vnand Rn are the voltage across resistors n and its resistance.

Req = ∑ is the equivalent resistance and Vs is the source voltage. The power
dissipated in each resistor is given by

Fig. 1 Series connected resister

In this circuit with seven resistors connected in series.

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.

Enter the value of Vs and Rs

Vs = 24V, R1 = 20Ω, R2 = 14Ω, R3 = 12Ω, R4 = 18Ω, R5 = 8Ω,

R6 = 15Ω, R7 = 10Ω

Programme:-
%The program calculates the voltage across each resistor

%in a circuit that has resistors connected in series.

vs=input('Please enter the source voltage');

Rn=input('Enter the values of the resistors as elements in a row vector\n');

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('Resistance Voltage Power')


SHRINATHJI INSTITUTE OF TECHNOLOGY & ENGINEERING, NATHDWARA
Number of Experiment
SYSTEM PROGRAMMING LAB
DEPARTMENT OF ELECTRICAL Code: 5EE9A No.: 5
Pg No.7/7

disp('(Ohms) (Volts) (Watts)')

disp('')

disp(Table)

disp('')

fprintf('The current in the circuit is %f Amps.',i)

fprintf('\nThe total power dissipated in the circuit is %f Watts.',Ptotal)

Result:- we obtain various parameters and table

Please enter the source voltage24

Enter the values of the resistors as elements in a row vector

[20 14 12 18 8 15 10]

Resistance Voltage Power

(Ohms) (Volts) (Watts)

20.0000 4.9485 1.2244

14.0000 3.4639 0.8571

12.0000 2.9691 0.7346

18.0000 4.4536 1.1019

8.0000 1.9794 0.4897

15.0000 3.7113 0.9183

10.0000 2.4742 0.6122

The current in the circuit is 0.247423 Amps.

The total power dissipated in the circuit is 5.938144 Watts .

You might also like