Vous êtes sur la page 1sur 6

Algorithm-1 Finding root using bisection method Step 0 Define the equation, f(x) = 0.

Step 1 Read epsilon, the desired accuracy Step 2 Read two initial values x0 and x1 which bracket the desired root Step 3 Compute y0 = f(x0) Step 4 Compute y1 = f(x1) Step 5 Check if y0y1 < 0, then go to step 6 Else go to step 2 Step 6 Compute x2 = (x0+x1)/2 Step 7 Compute y2 = f(x2) Step 8 Check if y0y2 > 0, then set x0 = x2 Else set x1 = x2 Step 9 Check if | (x1-x0)/x1| > epsilon, then go to step 3 Step 10 Write x2,y2 Step 11 End Algorithm-2 Computation of a root of f(x) = 0, by Newton-Raphson method Step 0 Define f(x), f(x) Step 1 Input x0, epsilon, maxit Step 2 Set i=0 Step 3 Set f0=f(x0) Step 4 Compute df0=f(x0) Step 5 Set x1=x0-f(x0) Step 6 Set i=i+1 Step 7 Check if |(x1-x0)/x1|<epsilon, then print Root is, x1 and stop Else if i<n, then set x0 = x1 and go to step 3 Step 8 Write Iteration do not converge Step 9 End Algorithm-3 To find a root of f(x) = 0, by Secant Method Step 1 Define f(x) Step 2 Input x0,x1,error,maxit Step 3 Set i =1 Step 4 Compute f0=f(x0) Step 5 Compute f1 = f(x1) Step 6 Compute x2 = [(x0f1-x1f0)/(f1-f0)] Step 7 Set I = i+1 Step 8 Compute accy=|x2-x1|/|x1| Step 9 Check if accy<error, then go to step 14 Step 10 Check if I >= maxit then go to step 16 Step 11 Set x0 = x1

Step 12 Step 13 Step 14 Step 15 Step 16 Step 17

Set x1=x2 Go to Step 6 print Root = , x2 Go to Step 17 Print Iteration do not converge End

Algorithm-4 Computing root of an equation by Regula-Falsi Method Step 1 Define f(x) Step 2 Read epsilon, the desire accury Step 3 Read maxit, the maximum no. of iterations Step 4 Read x0, x1 two initial guess values of root Step 5 Compute f0=f(x0) Step 6 Compute f1=f(x1) Step 7 Check if f0f1 < 0, then go to the next step Else go to step 4 Step 8 Compute x2=[(x0f1-x1f0)/(f1-f0)] Step 9 Compute f2=f(x2) Step 10 Check if |f2|<epsilon, then go to step 18 Step 11 Check if f2f0 < 0then go to the next step Step 12 Set x1=x2 Step 13 Set f1=f2 Step 14 Go to Step 7 Step 15 Set x0=x2 Step 16 Set f0=f2 Step 17 Go to step 7 Step 18 Write Root =, x2,f2 Step 19 End

Algorithm-5 Evaluation of a polynomial and its derivative by Hornors method..(Birge-vieta Method) Step 1 Read n,a0,a1,a2,..an Step 2 Read x Step 3 Set i=n Step 4 Set p=an, q=an Step 5 Compute p=ai-1 + x*p Step 6 Check if i= 0, then go to step 5 Step 7 Set i=i+1 Step 8 Check if i<0, then go to step 5 Step 9 Write x, p value =, p, q value =, q Step 10 End

Algorithm-6 Computation of a root of f(x)=0, by linear iteration Step 0 Define g(x), where f(x)=0, is rewritten as x=g(x) Step 1 Input x0, epsilon, maxit Step 2 Set i=0 Step 3 Set x1=g(x0) Step 4 Set i=i+1 Step 5 Check, if |(x1-x0)/x1|<epsilon, then print root is, x1 Else go to step 6 Step 6 Check, if i<n, then set x0=x1 and go to step 3 Step 7 Write No convergence after, n, iterations Step 8 End

Algorithm-7 To compute f(x) by Langrages Interpolation Step 1 Read n Step 2 Read values of xi,fi for i=1,2,..n. Step 3 Set sum = 0, i=1 Step 4 Read x Step 5 Set j=1,product=1 Step 6 Check if j=I product = peoduct * (x-xj)/(xi-xj)/////////////////////////// j is not equal toi Else go to step 7 Step 7 Set j=j+1 Step 8 Check if i>n, then go to step 9 Else go to step 6 Step 9 Compute sum=sum+ product* fi Step 10 Set i=i+1 Step 11 Check if i>n then go to step 12 Else go to step 5 Step 12 Write x, sum

Algorithm-8 Fitting a straight line y = a+ bx. Step 1 Read n Step 2 Initialize : sum = 0, sum x2=0, sumy = 0, sumxy=0 Step 3 For j = 1 to n compute Begin Read data xj, yj Compute sum x = sum x + xj

Compute sum x2 = sum x2 + xj*xj Compute sum y = sum y + yi*yj Compute sum xy = sum xy + xj * yj End Compute b=(n*sum xy sum * sum y)/(n * sum x2-(sum x)2) Compute x bar = sum x/n Compute y bar = sum y/n Compute a = y bar b * x bar Compute a = y bar b * x bar Write a, b For j=1 to n Begin Compute y estimate = a + b * x; Write xj, yj, y estimate End Step 11 Stop Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 Step 10

Algorithm-9 Evaluate Trapezodial rule. Step 0 Define function f(x) Step 1 Initialize a, b, n Step 2 Compute h=(b-a)/n Step 3 Set x= a, s=0 Step 4 Compute x=x+h Step 5 Compute S=S+f(x) Step 6 Check if x<b, then go to step 4 Else go too the next step Step 7 Compute I = [hs+(f(a) + f(b))]/2 Step 8 Output I, n

Algorithm-10 Evaluation of Simpsons one-third rule Step 0 Define f(x) Step 1 Input a, b, n Step 2 Compute h=(b-a)/n Step 3 Compute S1=f(a) + f(b) Step 4 Set s2 = 0, x=a Step 5 Compute x= x+2h Step 6 Compute S2=S2+f(x) Step 7 Check if x<b then go to step 5 Else go to next step Step 8 Compute x= a+h

Step 9 Copute S4=S4+f(x) Step 10 Compute x+x+2h Step 11 Check f x>b go to next step Else go to step 9 Step 12 Compute i= [S1+4S4+2S2h]/3 Step 13 Write I, n

Algorithm-11 Solution of a system of Equation by Gauss-Seidel Iteratiom Method Step 1 Input elements aij of augmented matrix for i=1 to n, next, j=1 to n+1 Step 2 Input epsilon, maxit Step 3 Set xi = 0, for i=1 to n Step 4 Set big = 0, sum =0, j=1, k=1, iter = 0 Step 5 Check if k=j, set sum = sum + ajk xk/////////////////k is not equal to j Step 6 Check if k<n, set k=k+1, go to step 5 else Got o next step Step 7 Compute temp = (ajn+1 = sum)/ajj Step 8 Compute relerr = abs(xj-temp)/temp Step 9 Check if big < relerr then big = relerr Step 10 Set xj = temp Step 11 Set j = j +1, k=1 Step 12 Check if j<+n go to step 5 else go to next step Step 13 Check if relerr<epsilon then {Write iteration converge, and write xj for j =1 to N go to step 15} else if iter < maxit titer = iter + 1 go to step 5 Step 14 Write Iterations do not converge in , maxit iteration Step 15 Write xj for j = 1 to n Step 16 End Algorithm-12 Solution of first order differential equation by Runge-Kutta method of Order 2: Step 1 Define f(x,y) Step 2 Read x0, y0, h, xf Step 3 Repeat steps 4 to 11 until x1>xf Step 4 Compute k1=f(x0,y0) Step 5 Compute y1=y0+hk1 Step 6 Compute x1=x0+h Step 7 Compute k2=f(x1,y1) Step 8 Compute y1=[y0+h(k1+k2)]/2 Step 9 Write x1, y1 Step 10 Set x0 = x1 Step 11 Set y0=y1 Step 12 Stop Algorithm-13

Solution Function by Runge-Kutta method of order 4 Step 1 Define f(x,y) Step 2 Read x0, y0, h ,xf Step 3 Repeat step 4 to step 16 until x1>xf Step 4 Compute k1=hf(x0,y0) Step 5 Compute x= x0+(h/2) Step 6 Compute y = y0 + (k1/2) Step 7 Compute k2= h f(x, y) Step 8 Compute y = y0+(k2/2) Step 9 Compute k3=h f(x, y) Step 10 Compute x1=x0+h Step 11 Compute y=y0+k3 Step 12 Compute k4=h f(x1, y) Step 13 Compute y1 = y0 + [k1 + 2(k2 + k3) + k4]/6 Step 14 Write x1, y1 Step 15 Set x0 = x1 Step 16 Set y0 = y1 Step 17 Stop

Vous aimerez peut-être aussi