Documente Academic
Documente Profesional
Documente Cultură
Recall:
1∑
n
Mean(µ) = xi
n i=1
1 ∑
n
Variance = (xi − µ)2
n − 1 i=1
√
S.D. = Variance
12. Declare two arrays. First array will store weights of 10 boys (select random numbers between 10 to 60).
Second array will store heights of those 10 boys (select random numbers between 100 to 200). Write a
program which will count the numbers of boys whose weights is less than 40 kg and height is greater
than 170 cm.
EE6243/EE637 Assignment 1A Page 2 of 2
1
2 2
3 3 3
4 4 4 4
..
.
10 10 10 10 ··· 10
16. Write a program to display the following pattern using while loop:
1
2 3
4 5 6
7 8 9 10
17. Given a date, write a program that computes the day number in a year.
18. Implement the factorial function (do not use inbulit factorial function).
19. Write a program that generates an n-dimensional array of random values between 30 to 65 and sorts in
(a) ascending (b) descending order (do not use inbulit function for sorting).
20. Write a program that tabulates the first 100 prime numbers.
abs : returns the absolute value. If complex input, then returns magnitude
rand : to generate random number between 0 to 1.0
randi : generates random integers within the range
rem : rem(X,Y) returns the remainder after division of X by Y
sqrt : for square-root
input : displays the text in prompt and waits for the user to input a value and to press the Return key
display : for displaying the value of a variable in the command window
fprintf : writes data to text file or command window
NATIONAL INSTITUTE OF TECHNOLOGY ROURKELA
Department of Electrical Engineering
Soft Computing Techniques (EE6243/EE637)
Session: 2019 - 2020 (Autumn)
M.Tech. 1st Semester and Dual Degree 7th Semester
1. Generate a random matrix A(∈ R6×5 ) where all element ∈ [−1, 1]. Count the number of sign change in
A. Move row-wise.
2. Write a function that takes x and y as inputs from the main file and returns z, where,
√
z = 3x2 + (x2 + y 2 ) + eln(x)
3. Write a function that prints the binary equivalent of a positive integer number.
4. Differentiate the function f (x) = 3x2 − 1 at x = 5 using numerical differentiation techniques:
f (x + h) − f (x)
(a) Method 1: f ′ (x) =
h
f (x + h) − f (x − h)
(b) Method 2: f ′ (x) =
2h
x0 x1 x2 ··· xn
y0 y1 y2 ··· yn
x5 + 3x2 − 10 = 0
Start with a random guess. Update x iteratively until the new value is nearly equal to the old value.
Terminate if the difference is less than 10−5 or number of iterations is more than 50.]
7. Write a program that will read the value of x and evaluate the following function:
1, if x > 0
y = 0, if x = 0
−1, if x < 0
8. Plot y1 = sin(x) and y2 = cos(x) with x ∈ [0, 10π] on the same graph. Use two different colors. Take step
size as 0.1.
EE6243/EE637 Assignment 1B Page 2 of 4
9. Plot a circle with diameter 10 unit, center at (4,5) (do not use inbulit function for drawing the circle).
10. Plot ρ = θ2 with 0 ≤ ρ ≤ 5π in polar coordinates.
11. Step response of a standard second order system is given by
( √ )
e−ζωn t 1 − ζ 2
c(t) = 1 − √ sin ωd t + tan−1
1 − ζ2 ζ
(a) Plot the response for t ∈ [0, 30]s. Assume ωn = 1 rad/s, ζ = 0.2.
( )
e−ζωn t
√
(b) Indicate the exponential envelopes 1 ± 2
on the same figure.
1−ζ
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].
(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
∑
n
cos(x) ≈ C(x, n) = ci
i=0
where,
x2
ci = −ci−1 ; i = 0, 1, 2, . . . , n and c0 = 0
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 .
15. Find the value of sin(x) from the Taylor polynomial approximation
∑
n
x2i+1
sin(x) ≈ S(x, n) = (−1)i
i=0
(2i + 1)!
Compare the result. Use the termination criteria as stated in Problem No. 14.
16. The following sequences all converge to π:
∑
n
(−1)k+1
(an )∞
0 , an =4
2k − 1
k=1
( ) 12
∑
n
(bn )∞
0 , bn = 6 k −2
k=1
( ) 14
∑
n
(cn )∞
0 , cn = 90 k −4
k=1
6 ∑ (−1)k
n
(dn )∞
0 , dn =√
3 k=0 3k (2k + 1)
∑
n
(−1)k ∑ (−1)k
n
(en )∞
0 , en = 16 2k+1
−4 2k+1
5 (2k + 1) 239 (2k + 1)
k=0 k=0
Make a function for each sequence that returns an array with the elements in the sequence. Plot all the
sequences, and find the one that converges fastest toward the limit π.
17. (a) Write a function that take x̄ ∈ R2 and returns
(b) Write two separate functions for calculating the gradient (ḡ) and hessian matrix (H) of the above
functions, where,
[ 2 ]
9x1 − 5x2
ḡ =
16x2 − 5x1
[ ]
18x1 −5
H =
−5 16
18. Suppose we are given a number of discrete points (x1 , y1 ), (x2 , y2 ), …, (xn , yn ) read from a curve y = f (x),
where x is bounded between x1 and xn . We wish to approximate the area under the curve by breaking
up the curves into number of small rectangles and calculating the area of these reactangles (trapezoidal
rule). The appropriate formula is:
( ) ( ) ( )
x2 − x1 x3 − x2 xn − xn−1
A = (y1 + y2 ) + (y2 + y3 ) + . . . + (yn−1 + yn )
2 2 2
Write a program to implement this strategy, using a function to evaluate y = f (x). Use the program to
calculate the area under the curve y = x3 , between the limits x = 1 and x = 4. Solve this problem first
with 16 evenly spaced points, then with 61 points, and finally with 301 points.
19. Problem 18 describes trapezoidal rule to calculate area under a curve y = f (x). If the tabulated values of
x are equally spaced, the equation given in the preceding problem can be simplified to read
h
A= (y1 + 2y2 + 2y3 + 2y4 + · · · + 2yn−1 + yn )
2
where, h is the distance between successive values of x. Write a program to calculate the area under the
curve y = e−x , where, x ∈ [0, 1].
20. A normally distributed random variable x, with mean µ and standard deviation σ, can be generated from
the formula:
∑N
i=1 ri − N
x=µ+σ √ 2
N
12
where, ri is a uniformly distributed random number whose value lies between 0 and 1. Write a program
that will generate a specified number of normally distributed random variates with a given mean and
a given standard deviation. The number of random variates, the mean and the standard deviations are
inputs to the program.