0% found this document useful (0 votes)
15 views60 pages

Python Record

The document outlines the practical coursework for the I M Sc. Mathematics program at RVS College of Arts and Science for the academic year 2024-2025. It includes a detailed index of practical topics covered, such as calculating the area of a triangle, simple and compound interest, and various mathematical computations using Python. Each section provides an aim, algorithm, program code, output, and result for the respective practical exercises.

Uploaded by

Aiswarya
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)
15 views60 pages

Python Record

The document outlines the practical coursework for the I M Sc. Mathematics program at RVS College of Arts and Science for the academic year 2024-2025. It includes a detailed index of practical topics covered, such as calculating the area of a triangle, simple and compound interest, and various mathematical computations using Python. Each section provides an aim, algorithm, program code, output, and result for the respective practical exercises.

Uploaded by

Aiswarya
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/ 60

RVS COLLEGE OF ARTS AND SCIENCE

(AUTONOMOUS) SULUR, COIMBATORE - 641 402

2024 – 2025

DEPARTMENT OF MATHEMATICS
I M Sc. MATHEMATICS
VAP-II– MATHEMATICAL COMPUTATION USING PYTHON -PRACTICAL
Register No. : __________________

Certified to be the Bonafide Record of the Practical Work done by _________________________


submitted for the Practical Examination held by RVS College of Arts and science on ______________.

Faculty in Charge Head of the Department


(Dr. K. JEYA LEKSHMI) (Dr. M. INDHUMATHI)

Examiner
INDEX
S.NO. DATE TOPIC PAGE SIGNATURE
1. 04.12.2024 AREA OF THE TRIANGLE 1-2

2. 04.12.2024 SIMPLE AND COMPOUND INTREST 3-4

3. 11.12.2024 LARGEST THREE NUMBERS 5-6


4. 11.12.2024 ODD OR EVEN 7-8

5. 11.12.2024 LEAP YEAR 9-10


6. 04.01.2025 COMPARE TWO NUMBERS 11-12

7. 04.01.2025 CONVERT TEMPERATURE 13-14


8. 04.01.2025 LOGICAL OPERATOR 15-16

9. 23.01.2025 MAXIMIUM OF THREE NUMBERS 17-18


1
10. 23.01.2025 SQUARE ROOT 19-20
11. 23.01.2025 SUM OF NUMBERS 21-22

12. 30.01.2025 SUM OF NATURAL NUMBERS 23-24 1


13. 30.01.2025 FACTORS 25-26
3
14. 30.01.2025 PRIME NUMBER 27-28
1
15. 14.02.2025 FACTORIAL 29-30

16. 14.02.2025 LOGICAL AND 31-32


17. 14.02.2025 TRUE OR FALSE 33-34

18. 21.02.2025 CHECK AGE 35-36

19. 21.02.2025 DERIVATIVE OF ALGEBRAIC 37-38


FUNCTION
20. 21.02.2025 DERIVATIVE OF TRIGNOMETRIC 39-40 3
FUNCTION
21. 21.02.2025 DERIVATIVE OF EXPONENTIAL 41-42
2
FUNCTION
22. 28.02.2025 SECOND ORDER DERIVATIVE OF 43-44
ALGEBRAIC FUNCTION 1
23. 28.02.2025 PARTIAL DERIVATIVE OF 45-46
ALGERAIC FUNCTION
24. 28.02.2025 MIXED PARTIAL DERIVATIVE OF 47-48
EXPONENTIAL FUNCTION
25. 28.02.2025 MATRIX ADDITION 49-50

26. 14.03.2025 MATRIX SUBTRACTION 51-52


27. 14.03.2025 MATRIX MULTIPLICATION 53-54

28. 14.03.2025 ROW ECHELON MATRIX 55-56


29. 14.03.2025 RUNGE KUTTA METHOD OF 57-58
SECOND ORDER 6
Program:
Import math
a=int(input(“Enter the value of side a:”))
b=int(input(“Enter the value of side b:”))
c=int(input(“Enter the value of side b:”))
s=float(a+b+c)/2
Area=math.sqrt(s*(s-a)*(s-b)*(s-c))
Print(“ The Area of the triangle is”,Area)

Output:
Enter the value of side a:4
Enter the value of side b:6
Enter the value of side c:8
The Area of the triangle is:11.6189500

1
1. Area Of Triangle
Aim:
Find the area of triangle.

Algorithm:
Step-1:Start
Step-2:Enter the values of sides a,b,c
Step-3:S=(a+b+c)/2
Step-4:Area=sqrt(s*(s-a)*(s-b)*(s-c))
Step-5: Write “ The Area of the triangle is”,Area
Step-6:stop

Result:
Thus the program has been executed successfully.

2
Program:
Import math
P= int( input ( “Enter the principle amount:”))
N=int( input ( “Enter the no of years n:”))
R=int (input (“ Enter the rate of interest r:”))
SI=( p* n* r )/100
Print (“The Simple interest SI is:”, SI)
CI=p*( pow((1+r/100),n)-1)
Print (“ The Compund Interest CI is:”,CI)

Output :
Enter the principle amount p:1000
Enter the no of years n:5
Enter the rate of interest r:10
The simple interest SI is:500
The Compound Interest CI is:1464.1000

3
2. Simple Interest And Compound Interest
Aim:
Raja has borrowed 1000Rs at the of 10% simple interest and compound interest per annum from his friend
Ramu.He proposes to pay the amount borrowed with interest after 5 years.Calculate the amount Raja needs.

Algorithm:
Step-1: Start
Step-2: Read the value of P
Step-3: Read the value of n
Step-4: Read the value of r
Step-5: SI=( p* n* r )/100
Step-6: Write SI
Step-7: CI=p*( pow((1+r/100),n)-1)
Step-8: Write CI
Step-9: Stop

Result:
Thus the program has been executed successfull

4
Program:
Import math
A= int( input (Enter the value for a:”))
B= int( input ( “ Enter the value for b:”))
C= int( input (“ Enter the value of c:”))
If a>b:
Big=a
else:
Big = b
If c>big:
Big=c
Print (“ The largest of three”, “ a=”,a,”b=”,b,”c=”,c,”is”, big)

Output:
Enter the value for a:20
Enter the value for b:30
Enter the value for c:10
The largest of three a=20,b=30,c=10 is 30

5
3. Largest Three Numbers

Aim:
The largest among three integers using the values a=20,b=30,c=10

Algorithm:
Step-1: Start
Step-2: Read the values of a, b, c
Step-3: if a>b big=a
Step-4:else big=b
Step-5: if c>b big= c
Step-6:” write the largest of three numbers a, b, c is”, big
Step-7: Stop

Result:
Thus the program has been executed successfully.
6
Program:
# Program to check if a number is even or odd
Num = int(input(“Enter a number: “))
If num % 2 == 0:
Print(“Even”)
Else:
Print(“Odd”)

Output:
Enter a number:47
Odd
Enter a number:40
Even

7
4. Odd or Even

Aim:
Find a number whether it is even or odd

Algorithm:
Step-1: Start
Step-2: Enter the number
Step-3: if num%2==0
Step-4: The number is even
Step-5: else
Step-6: The number is odd
Step-7: Stop

Result:
Thus the program has been executed successfully.

8
Program:

# Program to check if a year is a leap year


Year = int(input(“Enter a year: “))

If (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


Print(year, “is a leap year”)
Else:
Print(year, “is not a leap year”)

Output:
Enter a year:2010
2010 is not a leap year
6.Compare Two Number

9
5. Leap year

Aim:.
Find a year whether it is a leap year or no

Algorithm:
Step-1: Start
Step-2: Enter the year
Step-3:if(year%4==0&year%100!=0)
Step-4:The year is a leap year
Step-5: else
Step-6:The year is not a leap year
Step-7:stop

Result:
Thus the program has been executed successfully.

10
Program:
# Program to compare two numbers using relational operators
Num1 = float(input(“Enter the first number: “))
Num2 = float(input(“Enter the second number: “))

# Relational operators
If num1 == num2:
Print(“Both numbers are equal.”)
Elif num1 > num2:
Print(f”{num1} is greater than {num2}.”)
Else:
Print(f”{num1} is less than {num2}.”)

Output:
Enter the first number:10
Enter the second number:15
10 is less than 15

11
6. Compare Two Number

Aim:
To compare two numbers using relational operators

Algorithm:
Step-1: Start
Step-2: Enter the first number
Step-3: Enter the second number
Step-4:if num1== num2
Step-5: Both numbers are equal
Step-6:elif num1>num2
Step-7:num1 is greater than num2
Step-8: else num1<num2
Step-9:num1 is less than num2
Step-10;Stop

Result:
Thus the program has been executed successful

12
Program:
# Program to convert temperature from Celsius to Fahrenheit
Celsius = float(input(“Enter temperature in Celsius: “))

# Conversion formula
Fahrenheit = (Celsius * 9/5) + 32

Print(“Temperature in Fahrenheit:”, Fahrenheit)

Output:
Enter temperature in celcius:50
Temperature in Fahrenheit:122

13
7. Convert Temperature

Aim:
To convert Temperature from celcius to Fahrenheit

Algorithm:
Step-1: Start
Step-2: Enter the temperature in celcius
Step-3: Fahrenheit=( celcius*9/5)+32
Step-4: “ Temperature in Fahrenheit:”, Fahrenheit
Step-5: Stop

Result:
Thus the program has been executed successfully

14
Program:
# Program to demonstrate logical operators
Age = int(input(“Enter your age: “))
Income = float(input(“Enter your annual income: “))

# Logical operators
If age >= 18 and income >= 50000:
Print(“You are eligible to apply for a loan.”)
Else:
Print(“You are not eligible for a loan.”)

Output:
Enter your age: 20
Enter your annual income: 73000
You are eligible to apply for a loan.

15
8. Logical operator

Aim:
Demonstrate logical operators

Algorithm:
Step-1: Start
Step-2: Enter the age
Step-3:Enter the income
Step-4: Using the logical operator if check age is>18 and income is >=50000
Step-5: You are eligible to apply for a loan
Step-6: else
Step-7: You are not eligible to apply for a loan
Step-8:Stop

Result:
Thus the program has been executed successfully

16
Program:
# Program to find the maximum number among three numbers
Num1 = float(input(“Enter the first number: “))
Num2 = float(input(“Enter the second number: “))
Num3 = float(input(“Enter the third number: “))

Max_number = max(num1, num2, num3)


Print(“Maximum number:”, max_number)

Output:
Enter the first number: 10
Enter the second number: 20
Enter the third number: 30
Maximum number: 30.0

17
9. Maximum of Three Numbers

Aim:
To find the maximum number among three numbers

Algorithm:
Step-1: Start
Step-2: Enter the first number
Step-3: Enter the second number
Step-4: Enter the third number
Step-5: max_ num =max(num1, num2, num3)
Step-6:”Maximum number:”,Max_num
Step-7: Stop

Result:
Thus the program has been executed successfully

18
Program:
# Program to calculate the square root of a number
Import math

Num = float(input(“Enter a number: “))


Sqrt_result = math.sqrt(num)
Print(“Square root:”, sqrt_result)

Output:
Enter a number: 25
Square root: 5.0

19
10. Square Root

Aim:
To find the square root of a number

Algorithm:
Step-1: Start
Step-2: Enter a number
Step-3: sqrt_result =math.sqrt(num)
Step-4:” Square root:”,sqrt_result
Step-5: Stop

Result:
Thus the program has been executed successfully

20
Program:
# Program to calculate the sum of numbers from 1 to n
N = int(input(“Enter a number: “))
Sum_result = sum(range(1, n + 1))
Print(“Sum:”, sum_result)

Output:
Enter a number: 4
Sum: 10

21
11. Sum Of Numbers

Aim:
To find the sum of numbers from 1 to n

Algorithm:
Step-1: Start
Step-2: Enter a number
Step-3:sum_ result=sum( range(1+n+1)(
Step-4:”Sum”,sum_ result
Step-5:Stop

Result:
Thus the program has been executed successfully

22
Program:
# Input: positive integer n
N = int(input(“Enter a positive integer: “))

# Initialize variables
Sum = 0
i=1

# Calculate the sum using a while loop


While i <= n:
Sum += i
i+= 1

# Display the result


Print(“The sum of natural numbers from 1 to”, N, “is:”, sum)

Output:
Enter a positive integer: 7
The sum of natural numbers from 1 to 7 is: 28

23
12. Sum Of Natural Numbers

Aim:
To find sum of natural numbers from 1 to n

Algorithm:
Step-1: Start
Step-2: Enter a positive integer
Step-3:Assign sum=0 &i=1
Step-4: Using while loop find the sum of numbers from 1 to n
Step-5: Print the sum from 1 to n
Step-6: Stop

Result:
Thus the program has been executed successfully.

24
Program:
# Input: positive integer num
num = int(input(“Enter a positive integer: “))

# Display factors using a for loop


Print(“Factors of”, num, “are:”)

For I in range(1, num + 1):


if num % I == 0:
Print(I)

Output:
Enter a positive integer: 4
Factors of 4 are:
1
2
4

25
13. Factors

Aim:
To find factors of the positive integer

Algorithm:
Step-1: Start
Step-2:Enter the positive integer
Step-3: Using for loop check the remainder is zero or not
Step-4: print the factors
Step-5: Stop

Result:
Thus the program has been executed successfully

26
Program:
# Input: positive integer num
Num = int(input(“Enter a positive integer: “))

# Check if the number is prime using if-else statement


if num> 1:
For i in range(2, int(num**0.5) + 1):
if num % i == 0:
Print(num, “is not a prime number.”)
break
else:
Print(num, “is a prime number.”)
else:
Print(num, “is not a prime number.”)

Output:
Enter a positive integer: 6
6 is not a prime number.
Enter a positive integer:5
5 is a prime number

27
14. Prime Number

Aim:
To find prime number of the positive integer

Algorithm:
Step-1: Start
Step-2: Enter a positive integer
Step-3: Using if else statement check the number is >1
Step-4:if the number is greater than 1 , using for loop check the number is prime or not
Step-5:if the number is prime print the number is prime
Step-6: Otherwise is not prime
Step-7:Stop

Result:
Thus the program has been executed successfully

28
Program:
Def factorial(n):
if n < 0:
Print(“Factorial is not defined for negative numbers.”)
elif n == 0 or n == 1:
return 1
else:
result = 1
For i in range(2, n + 1):
result *= i
return result

# Example usage
Number = int(input(“Enter a number: “))
Print(f”The factorial of {number} is: {factorial(number)}”)

Output:
Enter a number:4
The Factorial

29
15. Factorial

Aim:
To find factorial of a number

Algorithm:
Step-1: Start
Step-2: Enter a number
Step-3:Define a factorial function
Step-4: Using if statement check the number is <0
Step-5: if so print factorial is not defined for negative numbers
Step-6: if the number is 0 or 1, return 1
Step-7: if not, using for loop find the factorial of the number
Step-8:print factorial of a number
Step-9: Stop

Result:
Thus the program has been executed successfully

30
Program:
# Logical AND
Def logical_and_example(a, b):
if a > 0 and b > 0:
Print(“Both numbers are positive.”)
else:
Print(“At least one number is not positive.”)

# Example usage
Logical_and_example(5, 7)
Logical_and_example(-3, 8)

Output:
Both numbers are positive.
At least one number is not positive.

31
16. Logical AND

Aim:
To find both numbers are positive or not using logical AND operator

Algorithm:
Step-1: Start
Step-2:Define logical_and_ example (a,b) function
Step-3: Check a>0 and b>0 if so print both numbers are positive
Step-4:if not atleast one number is positive
Step-5:Stop

Result:
Thus the program has been executed successfully

32
Program:
Def check_number(num):
if num % 2 == 0 or num> 10:
return True
else:
return False

# Example usage
Number_to_check = 7
result = check_number(number_to_check)
Print(f”Is {number_to_check} either even or greater than 10? {result}”)

Output:
Is 7 either even or greater than 10? False

33
17. True Or False

Aim:
To check the result True or False

Algorithm:
Step-1: Start
Step-2: Assign number 7 to num
Step-3: Define a function check number
Step-4: if remainder is when divided by 2 or num>10, return True
Step-5: Otherwise return False
Step-6:Stop

Result:
Thus the program has been executed successfully

34
Program:
Def check_age(age):
if not (13 <= age <= 19):
return True
else:
return False

# Example usage
User_age = 25
result = check_age(user_age)
Print(f”Is the user with age {user_age} not a teenager? {result}”)

Output:
Is the user with age 25 not a teenager? True

35
18. Check Age

Aim:
To check the age whether it is between 13 & 19

Algorithm:
Step-1: Start
Step-2: Assign 25 to user age
Step-3:Define the function check age
Step-4: if age is not between 13 & 19, return True
Step-5: Otherwise return False
Step-6: Stop

Result:
Thus the program has been executed successfully

36
Program:
Import sympy as sp
# Define the variable and the function
x = sp.symbols(‘x’)
f = 3*x**2 + 2*x – 1
# Find the derivative
derivative_f = sp.diff(f, x)
# Print the result
Print(“original Function:”, f)
Print(“derivative:”, derivative_f)

OUTPUT
Original Function: 3*x**2 + 2*x - 1
Derivative:6x+2

37
19. Derivative of algebraic function

Aim:
To find the differentiation of algebraic function

Algorithm:
Step1: Start the program
Step2:Import the python library sympy for symbolic mathematics
Step3:Define the variable and the algrbraic function
Step4:Find the derivative of the function using sp.diff(f,x)
Step5: Print the result
Step6:End the program

RESULT:
Thus the program has been executed successfully.

38
Program:
import sympy as sp
# Define the variable and the function
x = sp.symbols('x')
g = sp.sin(x)
# Find the derivative
derivative_g = sp.diff(g, x)
# Print the result
print("Original Function:", g)
print("derivative:", derivative_g)

OUTPUT
Original Function: sin(x)
Derivative: cos(x)

39
20. DERIVATIVE OF TRIGONOMETRIC FUNCTION

Aim:
To find the differentiation of trigonometric function

Algorithm:
Step1: Start the program
Step2:Import the python library sympy for symbolic mathematics
Step3:Define the variable and the trigonometric function
Step4:Find the derivative of the function using sp.diff(g,x)
Step5: Print the result
Step6:End the program

RESULT:
Thus the program has been executed successfully.

40
Program:
import sympy as sp
# Define the variable and the function
x = sp.symbols('x')
h = sp.exp(2*x)
# Find the derivative
derivative_h = sp.diff(h, x)
# Print the result
print("Original Function:", h)
print("derivative:", derivative_h)

OUTPUT
Original Function: exp(2*x)
Derivative:2* exp(2*x)

41
21. DERIVATIVE OF EXPONENTIAL FUNCTION

Aim:
To find the differentiation of exponential function

Algorithm:
Step1: Start the program
Step2:Import the python library sympy for symbolic mathematics
Step3:Define the variable and the exponential function
Step4:Find the derivative of the function using sp.diff(h,x)
Step5: Print the result
Step6:End the program

RESULT:
Thus the program has been executed successfully.

42
Program:
import sympy as sp
# Define the variable and the function
x = sp.symbols('x')
f = x**3 + 2*x*2 - 4*x + 1
# Find the second derivative
second_derivative_f = sp.diff(f, x, 2)
# Print the result
print("Original Function:", f)
print("Second Derivative:", second_derivative_f)

OUTPUT
Original Function: x**3 + 2*x*2 - 4*x + 1
Second Derivative:2*(3*x+2)

43
22. Second order Derivative

Aim:
To find the second order derivative of algebraic function

Algorithm:
Step1: Start the program
Step2:Import the python library sympy for symbolic mathematics
Step3:Define the variable and the algebraic function
Step4:Find the derivative of the function using sp.diff(f,x,2)
Step5: Print the result

RESULT:
Thus the program has been executed successfully.

44
Program:
import sympy as sp
# Define the variables and the function
x, y = sp.symbols('x y')
f = 2*x*2 + 3*x*y - y*2
# Find the partial derivatives
partial_derivative_x = sp.diff(f, x)
partial_derivative_y = sp.diff(f, y)
# Print the results
print("Original Function:", f)
print("Partial Derivative with respect to x:", partial_derivative_x)
print("Partial Derivative with respect to y:", partial_derivative_y)

OUTPUT
Original Function: 2*x*2 + 3*x*y - y*2
Partial Derivative with respect to x: 4*x+3*y
Partial Derivative with respect to y: 3*x−2*y

45
23. PARTIAL DERIVATIVE OF ALGEBRAIC FUNCTION

Aim:
To find the partial derivative of algebraic function

Algorithm:
Step1: Start the program
Step2:Import the python library sympy for symbolic mathematics
Step3:Define the variable and the algebraic function
Step4:Find the derivative of the function with respect to x using sp.diff(f,x)
Step5:Find the derivative of the function with respect to y using sp.diff(f,y)
Step6: Print the result

RESULT:
Thus the program has been executed successfully.

46
Program:
import sympy as sp
# Define the variables and the function
x, y = sp.symbols('x y')
h = sp.exp(x*y)
# Find the mixed partial derivatives
partial_derivative_xy = sp.diff(h, x, y)
partial_derivative_yx = sp.diff(h, y, x)
# Print the results
print("Original Function:", h)
print("Mixed Partial Derivative (d/dx d/dy):", partial_derivative_xy)
print("Mixed Partial Derivative (d/dy d/dx):", partial_derivative_yx)

OUTPUT
Original Function: exp(x*y)
Mixed Partial Derivative (d/dx d/dy): (x*y+1)* exp(x*y)
Mixed Partial Derivative (d/dy d/dx): (x*y+1)* exp(x*y)

47
24. MIXED PARTIAL DERIVATIVE OF EXPONENTIAL FUNCTION

Aim:
To find the mixed partial derivative of exponential function

Algorithm:
Step1: Start the program
Step2:Import the python library sympy for symbolic mathematics
Step3:Define the variable and the exponential function
Step4:Find the derivative of the function with respect to x using sp.diff(h,x,y)
Step5:Find the derivative of the function with respect to y using sp.diff(h,y,x)
Step6: Print the result

RESULT:
Thus the program has been executed successfully.

48
Program:
import numpy as np
# Define matrices A and B
A = np.array([[2, 3], [4, 1]])
B = np.array([[-1, 5], [2, 0]])

# Perform matrix addition


result = A + B

# Display the result


print("Matrix A:")
print(A)
print("\nMatrix B:")
print(B)
print("\nMatrix Addition (A + B):")
print(result)

Output:
Matrix A:
[[2 3]
[4 1]]

Matrix B:
[[-1 5]
[ 2 0]]

Matrix Addition (A + B):


[[1 8]
[6 1]]

49
25. Matrix addition

Aim:
To find the matrix addition

Algorithm:
Step 1: start the program
Step 2: import the python library numpy for symbolic mathematics
Step3: Define the variable and algebraic function
Step4: Find the addition of two matrix.
Step 5: print the result
Step6 : End the program

Result:
The program has been executed successfully.

50
Program:
import numpy as np
# Define matrices A and B
A = np.array([[2, 3, 1], [4, 1, 5], [6, 2, 3]])
B = np.array([[1, 5, 2], [3, 2, 1], [0, 4, 2]])

# Perform matrix subtraction


result_subtraction = A - B

# Display the result


print("Matrix A:")
print(A)
print("\nMatrix B:")
print(B)
print("\nMatrix Subtraction (A - B):")
print(result_subtraction)

Output:
Matrix A:
[[2 3 1]
[4 1 5]
[6 2 3]]

Matrix B:
[[1 5 2]
[3 2 1]
[0 4 2]]

Matrix Subtraction (A - B):


[[ 1 -2 -1]
[ 1 -1 4]
[ 6 -2 1]]

51
26. Matrix subtraction:

Aim:
To find the matrix subtraction

Algorithm:
Step 1: start the program
Step 2: import the python library numpy for symbolic mathematics
Step 3: Define the variable and algebraic function
Step 4: Find the subtraction of two matrix.
Step 5: print the result
Step 6 : End the program

Result:
The program has been executed successfully.

52
Program:
import numpy as np
# Define matrices A and B
A = np.array([[2, 3], [4, 1]])
B = np.array([[5, 2], [1, 6]])

# Multiply matrices A and B


C = np.dot(A, B)

print("Matrix A:")
print(A)
print("\nMatrix B:")
print(B)
print("\nResult of A * B:")
print(C)

Output:
Matrix A:
[[2 3]
[4 1]]

Matrix B:
[[5 2]
[1 6]]

Result of A * B:
[[13 22]
[21 14]]

53
27. Matrix multiplication

Aim:
To find the matrix multiplication

Algorithm:
Step 1: start the program
Step 2: import the python library numpy for symbolic mathematics
Step3: Define the variable and algebraic function
Step4: Find the multiplication of two matrix.
Step 5: print the result
Step 6 : End the program

Result:
The program has been executed successfully.

54
Program:
import numpy as np
#Define the matrix
Matrix = np.array([
[2, 3, -1, 1],
[4, 5, 1, 2],
[6, 7, 2, 3]
], dtype=float)
# Perform row operation to get row echelon form
Matrix[1] -= 2 * Matrix[0]
Matrix[2] -= 3 * Matrix[0]
Matrix[2] -= 2 * Matrix[1]

#Make the leading coefficients 1


Matrix[1] *=-1
Matrix[2] *=-1
#Display the row echelon form
Print(“Row echelon form:”)
Print (Matrix)

Output:

Row echlon form:


[[2. 3. -1. 1.]
[0. 1. -3. 0.]
[0. 0. 1. 0.]]

55
28. Row echlon matrix

Aim:
To find the matrix of row echlon

Algorithm:
Step 1: start the program
Step 2: import the python library numpy for symbolic mathematics
Step3: Define the augumented matrix and perform row operation to get row echlon form.
Step4: write the coding to make the leading coefficient.
Step 5: print the result
Step6 : End the program

Result:
The program has been executed successfully.

56
Program:
def rk2_solver(f, y0, t0, tf, h):
# Runge-Kutta 2nd order method [By Bottom Science]
t = t0
y = y0
while t <= tf:
k1 = h * f(t, y)
k2 = h * f(t + h, y + k1)
y = y + (k1 + k2) / 2
t=t+h
return y

def f(t, y):


return t + y

y0 = 1
t0 = 0
tf = 0.1
h = 0.1
y_sol = rk2_solver(f, y0, t0, tf, h)
print("Solution at t =", tf, "is", y_sol)

Output:
Solution at t=0.1 is : 1,24205

57
29. Runge Kutta Method Of Second Order

Aim:
To find the dy/dx=x+y by using Rungekutta method of second order for the values at t=0.1

Algorithm:
Step1:Start the program
Strp2: Define the function with the argument (f,y0,t0,tf,h)
Step3:Assign the values t0 and y0 to t and y
Step4:Using while loop find the values of k1,k2,y,t till t<=f
Step5:Return y
Step6:Define the function f(t,y) and return t+y
Step7:Assign the values of t0,y0,tf,h
Step8:Print the result
Step9:End the program

Result:
Thus the program has been executed successfully.

58

You might also like