Newton Raphson Method

#  Newton Raphson Method
# The Newton-Raphson method (also known as Newton's method) is a way
# to quickly find a good approximation for the root of a real-valued function


xcube=int(input('Enter the values for Xcube: '))

xsquare=int(input('Enter the values for Xsquare: '))

x=int(input('Enter the values for X: '))

constant=int(input('Enter the values for Constant: '))

X0=int(input('Enter the values for inital vaule X0: '))
 # It can be any value, but based on the incorrectness the root convergence
 #  will delay. Here we can use trail and error method for input value.
X1= X0-((((xcube*X0*X0*X0)+(xsquare*X0*X0)+(x*X0)+constant)/((xcube*3*X0*X0)+(xsquare*2*X0)+x)))

print ("Root at first approximations:",X1)

X2= X1-((((xcube*X1*X1*X1)+(xsquare*X1*X1)+(x*X1)+constant)/((xcube*3*X1*X1)+(xsquare*2*X1)+x)))

print ("Root at second approximations:",X2)

X3= X2-((((xcube*X2*X2*X2)+(xsquare*X2*X2)+(x*X2)+constant)/((xcube*3*X2*X2)+(xsquare*2*X2)+x)))

print ("Root at thrid approximations:",X3)

X4= X3-((((xcube*X3*X3*X3)+(xsquare*X3*X3)+(x*X3)+constant)/((xcube*3*X3*X3)+(xsquare*2*X3)+x)))

print ("Root at fourth approximations:",X4)

X5= X4-((((xcube*X4*X4*X4)+(xsquare*X4*X4)+(x*X4)+constant)/((xcube*3*X4*X4)+(xsquare*2*X4)+x)))

print ("Root at fifth approximations:",X5)

To read a coordinate point in a XY coordinate system and determine its Quadrant

x=int(input('Enter the values for X'))
 
y=int(input('Enter the values for Y'))

if x > 0 and y > 0:
  print ('x, y point lies in the First quandrant')
 
elif x < 0 and y > 0:
  print ('x, y point lies in the Second quandrant')
 
elif x < 0 and y < 0:
  print ('x, y point lies in the Third quandrant')

elif x > 0 and y < 0:
  print ('x, y point lies in the Fourth quandrant')

elif x == 0 and y == 0:
  print ('x, y point lies at the origin')

Reading files into Python

f = open("1.txt")
#create a text file which consists of names of students in class
# Printing file all the names
print("File contnet as in text file:",f.read())
f = open("1.txt")
# Printing file one by one letters
print("\nFile contnet one by one word fromtext file:")
next = f.read(1)
while next != "":
    print(next)
    next = f.read(1)

Multiplication of two Matrices

X = [[4,1,7],[2,1,8],[3 ,7,1]];
Y = [[6,8,1],[9,7,5],[2,3,1]];
result = [[0,0,0],[0,0,0],[0,0,0]];
        
for i in range(len(X)):
     for j in range(len(Y[0])):
         for k in range(len(Y)):
             result[i][j] += X[i][k] * Y[k][j]

for r in result:
 print(r)

Mathematical operators on Numpy Array and List

import numpy as np

a = np.array([1, 2, 3])
print(type(a))           
print('Numpy Array:\n',a)
print('Addition of Numpy Arrays with constant:\n',a+13)
print('Addition of Numpy Arrays:\n',a+a)
print('Multiplication of Numpy Arrays with constant:\n',a*3)
print('Multiplication of Numpy Arrays with another:\n',a*a)
print('Divison of Numpy Arrays with constant:\n', a/3)
print('Divison of Numpy Arrays with another:\n', a/a)
print('Power of Numpy Arrays with constant:\n', a**4)
print('Power of Numpy Arrays with another:\n', a**a)
print('Remainder of Numpy Arrays with constant:\n',a%2)
print('Remainder of Numpy Arrays with another:\n',a%a)
print('Subtraction of Numpy Arrays with constant:\n', a-1)
print('Subtraction of Numpy Arrays with another:\n', a-a)

try:
  a1=[1, 2, 3]
  print('\n',type(a1))
  print('Common List:\n', a1)
  print('Addition of Lists:\n',a1+a1)
  print('Multiplication of List with constant:\n',a1*3)
  print(a1+13) #error
  print(a1*a1) #error
  print(a1/3) #error
  print(a1/a1) #error
  print(a1**4) #error
  print(a1*a1) #error
  print(a1%2) #error
  print(a1%a1) #error
  print(a1-1) #error
  print(a1-a1) #error
except TypeError:
  print('TypeError')