Lectutre 6t07
Lectutre 6t07
Programming In MATLAB
• 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
3
Basic Commands
4
Input Command
5
Input Command
Matlab Returns:
R=
40
6
Pause Command
• pause causes a procedure to stop and wait for the user to strike
any key before continuing.
7
Pause Command
pause
8
Pause Command
pause(3)
9
Keyboard Command
• keyboard, when placed in an M-file, stops execution of the file
and gives control to the user's keyboard
10
Keyboard Command
keyboard
11
Display Command
12
Display Command
• disp(x) displays the variable value on the screen without
printing its name.
>> a=3;
>> disp(a)
3
13
sprintf Command
• sprintf(‘%g’,x) displays the variable value on the screen.
• sprintf(‘ the value is %g’,x) displays the variable value on
the screen.
>> a=3;
>> sprintf(‘ the value of a is = %g’, a)
the value of a is = 3
14
Exercise#1
1. Write down MATLAB code that accepts resistor values in following
manner.
– Enter number of 5k resistors
– Enter number of 10k resistors
– Enter number of 13K resistors
2. After entering the values wait for 5sec and again accepts following
values.
– Enter number of Si diodes
– Enter number of Ge diodes
– Enter number of GaAs diodes
15
Exercise#1 (contd…)
3. After Storing the values computer displays all the entered values one
by one by pressing the key from key board .
4. Display total number of resistors.
5. Display total number of diodes.
6. Display Total number of Components.
7. Display how much percent the resistors are among all the
components.
8. Display how much percent the diodes are among all the components.
16
Exercise#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.
17
Flow Control
18
Flow Control
• MATLAB has several flow control constructs:
– if
– switch and case
– For
– while
– Continue
– Break
– try – catch
– return
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
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.
21