Asma Maryam: Numerical Analysis Lab Page 1 of 4
Asma Maryam: Numerical Analysis Lab Page 1 of 4
2019-CH-424
Asma Maryam
Numerical Analysis Lab Page 2 of 4
Date: Experiment No # 05
Introduction to MATLAB
Objective:
To get familiar with Nested Loop.
Apparatus:
MATLAB Software
Personal Computer (PC)
Syntax:
for index = values
for index = values
statements
end
end
Procedure:
1. I opened MATLAB in my PC and set its layout as default so that I can view
command window, workspace command history and current folders.
2. I clicked on new script icon to open editor window and saved it. I wrote y= input
(value of y) so that every time I run the program command window will prompt to
enter value of y.
3. Then I created a variable an equal to length of y and a variable t=a-1.
4. I created a zero matrix having columns equal to rows equal the double of y plus one
so that I can get the difference printed between the two numbers.
5. Then I created a for loop to read the value of y in zeros matrix.
6. To get the difference table I created a nested loop and read the value of difference in
correct position in zeroes matrix to obtain fan like table.
7. I used command disp (‘Difference table’) to display it in command window.
8. Then I used display the table by using disp (‘d’) command.
Precautions:
We must write carefully in command window because MATLAB is case sensitive and
gives error.
Command window give one step execution so foe loop is never recommended in
command window.
The location to save any program must be specified just after opening the MATLAB.
Don’t mess with the address bar.
Clear command window and all variables in workspace before starting your work.
While saving any program name the program without space and using lowercase letter
otherwise MATLAB will give error.