Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
34 views9 pages

Numerical Analysis Lab-5

The document provides examples of MATLAB code to demonstrate numerical analysis concepts like looping, conditional statements, and relational operators. It includes code snippets to calculate sums of sequential numbers using for loops, check if inputs match certain conditions using if/else statements, and validate triangles and solve quadratic equations. The document contains instructions and sample programs for students to practice these MATLAB programming concepts.

Uploaded by

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

Numerical Analysis Lab-5

The document provides examples of MATLAB code to demonstrate numerical analysis concepts like looping, conditional statements, and relational operators. It includes code snippets to calculate sums of sequential numbers using for loops, check if inputs match certain conditions using if/else statements, and validate triangles and solve quadratic equations. The document contains instructions and sample programs for students to practice these MATLAB programming concepts.

Uploaded by

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

NUMERICAL ANALYSIS LAB

NS-321L
LECTURE – 5: PROGRAMMING - I
Write some lines of code that will
calculate the sum 1+2+3+...+300.
Hint: for loop
% Matlab code to sum the first
300 numbers

s = 0;
for i=1:300,
s = s + i;
end
disp(s)
Modify your program to sum the first N numbers,
and set N equal to 1000, 10000, and 100000 to see
what sum you get.
% Matlab code to sum the first N
numbers

N = 100000;

s = 0;
for i=1:N,
s = s + i;
end
s
Relational Operators in MATLAB

EXAMPLE PROGRAM:
a = input('Enter number: ');
if (a == 1)
disp('one')
else
disp('not one')
end
Logical Operators in MATLAB

EXAMPLE:
a = input('Enter number: ');
b = input('Enter number: ');
if (a&&b == 1)
disp('both non zero')
else
disp('at least one number is zero')
end
IF… Else Exercise
1. Write a program to check whether a number is negative, positive or
zero.
2. Write a program to input month number and print number of days in
that month
Assignment

•Write some lines of code to calculate the sum 12 + 22 +32 + ... 4002.
•Write some lines of code to calculate the sum 1·2+2·3+3·4+ ... + 249·250.
•Write a program to input angles of a triangle and check whether triangle is
valid or not.
•Write a program to find all roots of a quadratic equation.

You might also like