MATLAB-4
MATLAB-4
BSCpE 4
Contents
Basic Commands
• ummation
• Taylor Series
• Substitution and simplification
Taylor Series Calculator
• Differential Calculus
• Integral Calculus
• Limits
Function Calculator
• Laplace Transform
• Fourier Transform
• Z-Transform
• And their respective inverses
2
Basic Commands
3
Input Command
4
Input Command
Matlab Returns:
R=
40
5
Pause Command
• pause causes a procedure to stop and wait for the user to strike
any key before continuing.
6
Pause Command
pause
7
Pause Command
pause(3)
8
Keyboard Command
• keyboard, when placed in an M-file, stops execution of the file
and gives control to the user's keyboard
9
Keyboard Command
keyboard
10
Display Command
11
Display Command
• disp(x) displays the variable value on the screen without
printing its name.
>> a=3;
>> disp(a)
12
sprintf Command
• sprintf(‘%g’,x) displays the variable value on the screen.
>> a=3;
the value of a is = 3
13
Activity #1
1. Write down MATLAB code that accepts resistor values in following
manner.
– Enter number of 5k resistors
2. After entering the values wait for 5sec and again accepts following
values.
– Enter number of Si diodes
14
Activity #1 (contd…)
3. After Storing the values computer displays all the entered values one
by one by pressing the key from key board .
7. Display how much percent the resistors are among all the
components.
8. Display how much percent the diodes are among all the components.
15
Activity #1 (contd…)
9. Modify your program in such a way that if user enters wrong number
of components he/she can correct it later on.
16
Flow Control
17
Flow Control
• MATLAB has several flow control constructs:
– if
– For
– while
– Continue
– Break
– try – catch
– return
18
IF-Statement
• The optional elseif and else keywords provide for the execution of alternate
groups of statements.
• An end keyword, which matches the if, terminates the last group of
statements.
19
IF-Statement
• The optional elseif and else keywords provide for the execution of alternate
groups of statements.
• An end keyword, which matches the if, terminates the last group of
statements.
20