ECL 201 : SCIENTIFIC COMPUTING LABORATORY

LAB Manual

EC 201 SCIENTIFIC COMPUTING LABORATORY.pdf

Model Questions for Scientific computing Lab

1. Write a program in python which can perform, addition, subtraction, multiplication & division of two numbers and display the results

# Program to perform addition, subtraction, multiplication & division of two numbers and display the results

number1 = input("First number: ")

number2 = input("Second number: ")

sum = int(number1) + int(number2)

sub = int(number1) - int(number2)

mul = int(number1) * int(number2)


print("The sum of given numbers is :",sum)

print("The diff of given numbers is :",sub)

print("The mul of given numbers is :",mul)

2. Write a python program to find the area of a circle

# Python program to find Area of a circle

r = 3

PI = 3.142

area = PI*(r*r)

print("Area is " ,area);

3. Write a program for solve the given equation in python

2x + 6y - z = 5

3y + 2z = 8

5x - y + 4z = 10

# program for assigning matrix values, inverse of matrix and displaying

# importing libraries

from scipy import *

from pylab import *

from numpy import *


A=array([[2,6,-1],[0,3,2],[5,-1,4]])# assigning the values to matrix A from the equation

b = array([5,8,10]) # assigning the values of b matrix


print("A matrix is")

print(A) # printing the A matrix

print("b matrix is")

print(b) #printing then b matrix

X=inv(A).dot(b) # calculating the values of x,y,z

print("X matrix is")

print(X) # printing the X matrix

# printing each values

print("the value of x is :",round(X[0],2))

print("the value of y is :",round(X[1],2))

print("the value of z is :",round(X[2],2))

4. Write a program for a function to find out the largest and smallest number from an array in python

def myfun(n):

max1= max(n)

min1 = min(n)

print("maximum value is ",max1)

print("minimum value is ",min1)


myfun([10,2,3,4,5,6,7])

5. Write a program for generating and plotting the given function in python

y = 5Cos(t)+sin(10t)

from numpy import *

from matplotlib.pyplot import *

# Get x values of the sine wave

t = arange(0, 10, 0.01);

# calculating the amplitude

y1 = 5*cos(t)

y2 = sin(10*t)

y = (y1)+y2

# plotting cos signals in subplot

rcParams["figure.figsize"] = (10,10) # changing the figure size

fig, axs = subplots(3)

axs[0].plot(t,y1)

axs[0].set_title("cos(t) signal ")

axs[1].plot(t,y2)

axs[1].set_title("sin(2*t) Signal")

axs[2].plot(t,y)

axs[2].set_title("5Cos(t)+sin(2t) Signal")

show() # showing the figure


6. Write a program in python for 10 times coin toss and show how many heads and tails are there

import random as rd

rlist=[]

for i in range(10):

# print(i)

flip = rd.randint(0,1)

rlist.append(flip)


print("Coin Toss result is :",str(rlist))

print("No of Heads :",rlist.count(1), "\nNo of Tails :",rlist.count(0))


7. Generate and plot the signal 7Sin(2πt) and show the histogram of the same

import random as rd

rlist=[]

for i in range(10):

# print(i)

flip = rd.randint(0,1)

rlist.append(flip)


print("Coin Toss result is :",str(rlist))

print("No of Heads :",rlist.count(1), "\nNo of Tails :",rlist.count(0))


8. Write a program in python to find the square of the max value in an array

import random as rd

rlist=[]

for i in range(10):

# print(i)

flip = rd.randint(0,1)

rlist.append(flip)


print("Coin Toss result is :",str(rlist))

print("No of Heads :",rlist.count(1), "\nNo of Tails :",rlist.count(0))


9. Write a program in python to find the square of the max value in an array

import random as rd

rlist=[]

for i in range(10):

# print(i)

flip = rd.randint(0,1)

rlist.append(flip)


print("Coin Toss result is :",str(rlist))

print("No of Heads :",rlist.count(1), "\nNo of Tails :",rlist.count(0))


10. Realize the given equation

y = 5Cos(2*pi*t)+3Sin(2*pi*t)

11. Write a program to find the largest number in a list in python

12. Write a python program to print only even numbers from a list

13. Write a program to find the largest number in a list in python

14. Generate and plot the signal 7Sin(2πt) and show the histogram of the same

Course Outcomes

CO 1 : Describe the needs and requirements of scientific computing and to familiarize one programming language for scientific computing and data visualization.

CO 2 : Approximate an array/matrix with matrix decomposition.

CO 3 : Implement numerical integration and differentiation.

CO 4 : Solve ordinary differential equations for engineering applications

CO 5 : Compute with exported data from instruments

CO 6 : Realize how periodic functions are constituted by sinusoids

CO 7 : Simulate random processes and understand their statistics.