Question

In: Computer Science

***Please code in Python Write another code Newton (in double precision) implementing the Newton-Raphson Method   (copy...

***Please code in Python

Write another code Newton (in double precision) implementing the Newton-Raphson Method
  (copy your Bisect code and modify).
  Evaluation of F(x) and F'(x) should be done in a subprogram FCN(x).
  The code should ask for input of: x0, TOL, maxIT (and should print output similar to Bisect code).
  Debug on a simple problem, like x2−3 = 0.
  Then use it to find root of F(x) in [1,2] with TOL=1.e-12.

Now consider the problem of finding zeros of
      G(x) = x−tan(x)   near x=99 (radians).

Are there any ? How many ? How do you know ?

Use your Newton code to find the zero of G(x) closest to x = 99 (radians) to 9 decimals ( use TOL=10−9,maxIT=20 ).
  Output your final approximate root, the residual, and how many iterations it took.


 

THIS IS MY CURRENT CODE FOR BISECTION:

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
from scipy.misc import derivative


def func(x):
return x*x*x+2*x*x+10*x-20;
def bisection(a,b,tol,maxit):
  
if (func(a) * func(b) >= 0):
print("You have not assumed right a and b\n")
return

c = a
ct=0;
while ((b-a) >= tol):
ct=ct+1;
# Find middle point
c = (a+b)/2

# Check if middle point is root
if (func(c) == 0.0):
break

# Decide the side to repeat the steps
if (func(c)*func(a) < 0):
b = c
else:
a = c
print("%d"%ct,end='');
print("\t%f"%c,end='');
print("\t%e"%func(c),end='');
print("\t%e"%(b-a),end='\n');
if(ct==maxit):
break;
print("root=%f"%c,end="");
print(", residual=%e"%(b-a),end="");
print(", in%d"%ct,end="");
print(" iters",end="\n");
  
  
  
# Driver code
# Initial values assumed
a =float(input("Enter a: "))
b = float(input("Enter b: "));
tol=float(input("Enter tol: "));
maxit=int(input("Enter maxit: "));
bisection(a, b,tol,maxit)

Solutions

Expert Solution

def func( x ):

    return x * x * x - x * x + 2

  

# Derivative of the above function

# which is 3*x^x - 2*x

def derivFunc( x ):

    return 3 * x * x - 2 * x

  

# Function to find the root

def newtonRaphson( x ):

    h = func(x) / derivFunc(x)

    while abs(h) >= 0.0001:

        h = func(x)/derivFunc(x)

          

        # x(i+1) = x(i) - f(x) / f'(x)

        x = x - h

      

    print("The value of the root is : ",

                             "%.4f"% x)

  

# Driver program to test above

x0 = -20 # Initial values assumed

newtonRaphson(x0)

  


Related Solutions

Write a funtion and apply multi-var. Newton-Raphson method.
Write a funtion and apply multi-var. Newton-Raphson method.
please write a java code, one for method and another for the Demo to: -Compute the...
please write a java code, one for method and another for the Demo to: -Compute the average age of all female students. -Compute the least amount of credits completed among males. Store the three arrays in the demo file. Print the results within the demo file. String []gender ={"F", "F", "M", "F", "F", "M", "M", "M", "M", "F", "M", "F", "M", "F", "F", "M", "M", "F", "M", "F"}; int []age = {18, 19, 19, 21, 20, 18, 24, 19, 21,...
Let . If we use Accelerated Newton-Raphson method to approximate the root of the equation ,...
Let . If we use Accelerated Newton-Raphson method to approximate the root of the equation , which of the following(s) is/are ture: (I)  is multiple root of order (II) Accelerated Newton-Raphson formula is : (III) The sequence  obtained by the Accelerated Newton-Raphson method converge to the root  quadratically.
Newton-Raphson Method.Kindly explain the method and use illustrations for clear understanding of concepts
Newton-Raphson Method.Kindly explain the method and use illustrations for clear understanding of concepts
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of...
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of scalar nonlinear equa-tions. Use these programs to compute approximations to real roots of the following equations: exp(x)−3x^2=0, (1) x^3=x^2+x+1, (2) exp(x) =1/(0.1 +x^2), (3) and x= 1 + 0.3 cos(x). (4) Use an error tolerance tol=10^(−12). Display the obtained approximations to the roots of these equations, and compare the number of iterations, starting with the same initial values x0 for bisection and Newton methods,...
Consider the Newton-Raphson method for finding root of a nonlinear function ??+1=??−?(??)?′(??), ?≥0. a) Prove that...
Consider the Newton-Raphson method for finding root of a nonlinear function ??+1=??−?(??)?′(??), ?≥0. a) Prove that if ? is simple zero of ?(?), then the N-R iteration has quadratic convergence. b) Prove that if ? is zero of multiplicity ? , then the N-R iteration has only linear convergence.
Implement in MATLAB the Newton-Raphson method to find the roots of the following functions. (a) f(x)...
Implement in MATLAB the Newton-Raphson method to find the roots of the following functions. (a) f(x) = x 3 + 3x 2 – 5x + 2 (b) f(x) = x2 – exp(0.5x) Define these functions and their derivatives using the @ symbol. For example, the function of part (a) should be f=@(x)x^3 + 3*x.^2 - 5*x + 2, and its derivative should be f_prime=@(x)3*x.^2 + 6*x - 5. For each function, use three initial values for x (choose between -10...
please show the steps and clear hand writing please show how to Derive the Newton-Raphson formula....
please show the steps and clear hand writing please show how to Derive the Newton-Raphson formula. Diagrams and explanations will be needed.
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Using Newton-Raphson method, find the complex root of the function f(z) = z 2 + z...
Using Newton-Raphson method, find the complex root of the function f(z) = z 2 + z + 1 with with an accuracy of 10–6. Let z0 = 1 − i. write program c++ or matlab
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT