0% found this document useful (0 votes)
61 views4 pages

Asma Maryam: Numerical Analysis Lab Page 1 of 4

This document discusses nested loops in MATLAB. It explains what a difference table and nested loop are. It then provides the syntax for a nested loop and a step-by-step procedure to create a difference table using nested loops in MATLAB. The procedure prompts the user to input a value, creates matrices to store the table, uses nested loops to calculate and store the differences, and displays the resulting table. It concludes by providing some precautions for writing code in MATLAB.

Uploaded by

Asma Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views4 pages

Asma Maryam: Numerical Analysis Lab Page 1 of 4

This document discusses nested loops in MATLAB. It explains what a difference table and nested loop are. It then provides the syntax for a nested loop and a step-by-step procedure to create a difference table using nested loops in MATLAB. The procedure prompts the user to input a value, creates matrices to store the table, uses nested loops to calculate and store the differences, and displays the resulting table. It concludes by providing some precautions for writing code in MATLAB.

Uploaded by

Asma Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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)

What is Difference Table?


A difference table is made by listing the terms of a sequence and its differences. It includes
the first differences, which is a sequence that lists the differences of two consecutive terms of
the original sequence.

What is Nested Loop?


A nested loop has one loop inside of another. These are typically used for working with two
dimensions such as printing stars in rows and columns as shown below. When a loop is
nested inside another loop, the inner loop runs many times inside the outer loop.
Numerical Analysis Lab Page 3 of 4

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.

9. I called the function in command window.


10. Then I typed “clc” in command window to clear the command window.
11. I typed “clear all” in command window to clear the Workspace.
12. During working on MATLAB I continue to save my work piece after every step so I
may not lose any data.
Numerical Analysis Lab Page 4 of 4

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.

You might also like