0% found this document useful (0 votes)
19 views

Slip 5

Uploaded by

payalwani73
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
19 views

Slip 5

Uploaded by

payalwani73
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
In SLIP 5 #Evaluate following expression on Python. 1,2,3,4], Find Length M, “xvZ"*"pqr”, Find L. #(c) s="Make In India’, Find (s[:7]) & (s[:9]). Me[1,2,3.4] print ("length ",len(M)) Letxyz"+"pqr" print(L) s="Make In India” print(s{:71) print(s[:9]) length 4 xYZpar Make In Make In 1 Use Python code to generate the square root of numbers from 21 to 49. import math print("square root of numbers from 21 to 49") for i in range(21,50): print(i,math.sqrt(i)) square root of numbers from 21 to 4¢ 21 4,58257569495584 22 4,69041575982343 23 4,795831523312719 24 4,898979485566356 25 5.8 26 5.0990195135927845 27 5,196152422706632 28 5.291582622129181 29 5,385164807134504 30 5.477225575051661 31 5.5677643628300215 32 5.656854249492381 33 5.744562646538025 3a 5.830951894845301 35 5.916079783099616 36 6.0 37 6.082762530298215 38 6.164414002968976 39 6.244997998398398 40 6. 32455532033675¢ 41. 6.4031242374328485 42 6.48074069840786 43 6.557438524302 44 6.6332495807108 45 6.708203932499368 46 6.782329983125268 47 6.855654600401044 48 6.928203230275508 49 7.0 Using Python code construct the following matrices. 41, An identity matrix of order 1 x 10. #2. Zero matrix of order 7 x 3. #3. Ones matrix of order 5 x 4 import numpy as np np-identity(10) print (i) -zeros([7,3]) print (z) -ones([5,4]) print (0) [[1. @. @. @. @, 8. @. 0 @. 2 [@. 1. 8. 0, @ @. @. 0 8. @ [@. 0. 1. 0, @, @, @. 0. 0. & [0 0. 6. 1. 0, 6. 0. 2. @ 8 [@. 0. 8. @. 1, @. @. 0. 8 @ [@. 0. 8. @. @ 1, @. 0. 8. @ [@. 0. 8. @. @ @. 1. 0. 0. @ [0. 0. 6. 0. 0. 6. 0. 1. 0. 8 [@. 0. 6. 0. 0.6.0. 0. 1. 0. [@. 0. 0. 8. 0. @ @ @ @ 1.]] [8. 8. @, [e. 0. @ [e. 0. @ [e. &. 0 [e. 0. @ [e. @. 0. [a. 0. 6 (fa. 1.1. (1.1.2 (1a (1.1.2 (1.2.4, # Using Linsolve conmand in python, solve the following system of Linear equations fx - 2y 432-7 fax tyez=4 #-3x 4 2y - 22 = -10 from synpy import * from synpy.abc import x,y,z AeMatrix(((1,-2,3,7],[2,1,1,4],[-3,2,-2,-10]]) solve_linear_systen_LU(A, [x,y,2]) {x: 2, yt -1, 2: 1} turite Python program to estimate a root of an equation f(x) = 3x*2 + 4x-10 using ‘Newton-Raphson method correct up to four decimal places. import math ‘function defination def F(x): return 3*x**244%%-10 # Defining derivative of function def g(x): return 6*x+4 def newtonRaphson(x0,e,N): print("\n\n*** NEWTON RAPHSON METHOD IMPLEMENTATION ***") step = 1 flag = 1 condition = True while condition: if @(x0) @. print("Divide by zero error!) break x1 = x0 = #(x0)/e(x0) print (*Iteration-Xd, x1 = X.6¢ and f(x1) = xe.6f* % (step, x1, #(x1))) x0 = xd step = step +1 if step > N: flag = @ break condition = abs(f(x1)) > e if flage=1: print(*\nRequired root is: %6F '%x1) else: print(*\nNot Convergent. ") # Input Section x@ = float(input('Enter how many correct decimal places ')) @ = float (input( ‘Tolerable Error: ")) N= int(input("Maximum Step: ')) # Starting Newton Raphson Method newtonRaphson(x,e,N) *#* NEWTON RAPHSON METHOD IMPLEMENTATION *** Iteration-1, x1 = 1.637500 and #(x1) = 4.594219 Iteration-2, x1 = 1.35188 and #(x1) = 0.331295 Iteration-3, x1 = 1.277186 and (x1) = 6.002352 Iteration-4, x1 = 1.276984 and #(x1) = @.000000 Required root is: 1.276984 ‘urite Python program to obtained the approximate real root of f(x)= x*3 - 4x - 9 fusing Regula-falsi method. # Defining Function def F(x): return x**3-x*2-2 # Implementing False Position Method def falsePosition(x@,x1,e): step = 2 print(*\n\n*#* FALSE POSITION METHOD IMPLEMENTATION ***") condition = True while condition X2 = xO = (x1-nO) * F(x0)/( F(x1) - F(x@) ) print(‘Iteration-%d, x2 = 20.6f and #(x2) = %0.6F' X (step, x2, #(x2))) Af F(x@) * G2) < 0: x= x2 else: x0 = x2 step = step +1 condition = abs(f(x2)) > e print(*\nRequired root is: %@.8f' % x2) # Input Section x® = float (input(‘Enter xe ')) x1 = float (input(‘Enter x1 ')) e = float(input( ‘Tolerable Error: *)) # Checking Correctness of initial guess values and false positioning Af F(x) * #(x2) > 0.0: print (‘Given guess values do not bracket the root.") print (‘Try Again with different guess values.') else: falsePosition(x®,x1,e) #** FALSE POSITION METHOD IMPLEMENTATION *** Iteration-1, x2 = 1.600000 and (x2) = -1.104000 Iteration-2, x2 = 1.742268 and (x2) = -0.195885 Iteration-3, x2 = 1.765259 and f(x2) = [email protected] Iteration-4, x2 = 1.768697 and (x2) = -0.004400 Iteration-5, x2 = 1.769205 and f(x2) = -0.000649 Iteration-6, x2 = 1.769279 and (x2) = -0.000096 Iteration-7, x2 = 1.769290 and (x2) = -0.000014 Iteration-8, x2 = 1.769292 and F(x2) = -.000002 Required root is: 1.76929207

You might also like