Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Assignment 1 Python Programming-1(2)

The document outlines an assignment for B.Tech. 4th Semester students at the National Institute of Technology Rourkela, focusing on Python programming tasks. Students are instructed to create separate programs for various problems, emphasizing the use of basic programming constructs without built-in functions. The assignment includes tasks such as calculating sums, implementing mathematical functions, and plotting graphs, with specific instructions for file organization and submission.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment 1 Python Programming-1(2)

The document outlines an assignment for B.Tech. 4th Semester students at the National Institute of Technology Rourkela, focusing on Python programming tasks. Students are instructed to create separate programs for various problems, emphasizing the use of basic programming constructs without built-in functions. The assignment includes tasks such as calculating sums, implementing mathematical functions, and plotting graphs, with specific instructions for file organization and submission.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NATIONAL INSTITUTE OF TECHNOLOGY ROURKELA

Department of Electrical Engineering


AI and ML Laboratory
Session: 2024 - 25 (Spring)
B.Tech. 4th Semester

Assignment 1: Python Programming

AL INSTITUTE OFWrite
Instructions: TECHNOLOGY
a separate program for each problem. Avoid using in-built functions as much as

ROURKELA
possible. Write your programs primarily using if-else statements and for loops. Save each file as Assign-
ment<#No>_Question<#No>.py. Keep all files in a folder and name the folder with your Roll Number. Zip the
folder and upload it to MS Teams for evaluation.

1. Given a list [2, 8, 10, 683, 45, 1, 996, 139, 190, 58, 730, 9, 800], split it into three different arrays with different
ranges: [0, 10), [10, 100), [100, 1000] and print. [5]
2. Write a program for calculation of sum of square of all odd integers between 1 to 100. [5]
3. Implement the factorial function (do not use inbulit factorial function). [5]
4. Write a function to check whether a number is prime or not. Write a program to get the sum of first 20
prime numbers. [10]
5. Given an array of real numbers x̄ ∈ Rn , find their mean, standard deviation and variance. Take n = 10.
(Do not use inbuilt functions for the same). [10]

Recall:
1∑
n
Mean(µ) = xi
n i=1
1 ∑
n
Variance = (xi − µ)2
n − 1 i=1

S.D. = Variance

6. Write a program to display the following pattern: [5]

1
2 2
3 3 3
4 4 4 4
..
.
10 10 10 10 ··· 10

7. Generate a random matrix A(∈ R6×5 ) where all element ∈ [−1, 1]. Count the number of sign change in
A. Move row-wise. [5]
8. Differentiate the function f (x) = 3x2 − 1 at x = 5 using numerical differentiation techniques: [10]

f (x + h) − f (x)
(a) Method 1: f ′ (x) =
h
f (x + h) − f (x − h)
(b) Method 2: f ′ (x) =
2h
CS2672 Assignment 1 Page 2 of 2

Take h = 10−2 . Compare accuracy.

9. Find the approximated value of cos(x) as [10]


n
cos(x) ≈ C(x, n) = ci
i=0

where,
x2
ci = −ci−1 ; i = 0, 1, 2, . . . , n and c0 = 1
2i(2i − 1)

and x is expressed in radians. Write a program that will take the value of x from user and then calculate
its cosine. Write the program in two different ways:
(a) Sum of the first n terms, where n is a positive integer that is read into the computer along with the
numerical value for x.
(b) Continue adding successive terms in the series until the value of the next term becomes smaller than
10−5 .

10. Store all digits of a number into an array. [10]


11. Plot a circle with diameter 10 unit, center at (4,5). [5]
12. Plot the probability density function of Normal Distribution. [10]

1 (x−µ)2
f (x|µ, σ 2 ) = √ e− 2σ 2
2πσ 2
Where µ = mean; σ 2 variance. Take, (a) µ = 0, σ 2 = 1; (b) µ = 0, σ 2 = 0.2; (c) µ = 2, σ 2 = 0.5;
(d) µ = −2, σ 2 = 0.5. Plot all the above on same graph.
13. Plot the following functions for v ∈ [−5, 5]. [10]
(a) Saturating linear function: 

0, if v < −0.5
ϕ(v) = v + 0.5, if − 0.5 ≤ v ≤ 0.5


1, if v > 0.5

(b) Symmetric (bipolar) saturating linear function:



−1,
 if v < −1
ϕ(v) = v, if − 1 ≤ v ≤ 1


1, if v > 1

(c) Binary sigmoid function:


1
ϕ(v) =
1 + e−αv
Take α = 0.1, 0.5, 1.0 and plot all three functions on the same figure.
(d) Hyperbolic tangent sigmoid function:

eαv − e−αv
ϕ(v) = tanh(αv) =
eαv + e−αv
Take α = 0.1, 0.5, 1.0 and plot all three functions on the same figure.

You might also like