Question

Consider the following function with a real variable, x: ?(?) = ?3 - 3?2 + 6?...

Consider the following function with a real variable, x:
?(?) = ?3 - 3?2 + 6? + 10
a. Write a Python function for the derivative of f(x) that takes x and returns the derivative of f(x). Take the derivative of f(x) analytically with respect to x before writing the function.

b. Write a Python code that approximately finds the real root, x0, of f(x) such that f(x0)~0 using the Newton-Raphson method. The code is expected to get an initial guess from a user using the input statement. At each iteration, the code is expected to print the iteration number, the new guess and the absolute value of f(x) at the guess. Iterations should stop when the absolute value of f(x) at the guess is less than 10-6.
Hint: Use a while loop to implement the Newton-Raphson method where each execution of the loop corresponds to an iteration. At each iteration, find a new guess for that iteration using the iterative expression for the Newton-Raphson method.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Note: Brother sometimes while uploading on HomeworkLib the indentations change. So, I request you to verify it with screenshot once. This is the link where I have saved the code too

https://trinket.io/python3/331d3c0b37

def func( x ):
return x * x*x-3*x*x+6*x+10
# Derivative of the above function
# which is 3*x^x - 2*x
def derivFunc( x ):
return 3*x*x-6*x+6
  
# Function to find the root
def newtonRaphson( x ):
h = func(x) / derivFunc(x)
while abs(func(x)) >= 1e-6:
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 =int(input("Enter initial guess: "));
newtonRaphson(x0)

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Consider the following function with a real variable, x: ?(?) = ?3 - 3?2 + 6?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 45-3. Modify the code used in Example 4 to find the root only at f(x)<0.01 using...

    45-3. Modify the code used in Example 4 to find the root only at f(x)<0.01 using Newton-Rephson Method without showing any iteration. Also find the root of equation, f(x) = x 9-3x -10, take initial guess, Xo=2 العقدة College of 9:05 mybb.qu.edu.ca Numerical Methods (Lab.) GENG 300 Summer 2020 5.1.2 Open Methods - Newton-Raphson Method f(x) *1+1 = x; - Matlab Code Example:4 function mynewtraph.t1.x0,-) XXO for ilin x - x - x)/1 x) disp 1 x) <0.01 break end...

  • 5.1.2 Open Methods - Newton-Raphson Method Xi+1= xi – FOTO Matlab Code Example:4 function mynewtraph (f,...

    5.1.2 Open Methods - Newton-Raphson Method Xi+1= xi – FOTO Matlab Code Example:4 function mynewtraph (f, f1,x0,n) Xx0; for ilin x = x - f(x)/f1(x); disp (li if f(x) <0.01 f(x))) break end end end Matlab Code from Chapra function [root, ea, iter)=newtraph (func,dfunc, xr, es,maxit,varargin) newtraph: Newton-Raphson root location zeroes 8 [root, ea, iter)-newtraph (func, dfunc, xr, es,maxit,pl,p2, ...): $uses Newton-Raphson method to find the root of fune input: func- name of function 8dfunc = name of derivative of...

  • Write a MATLAB function newtonRaphson(fx, x0, sigfig, maxIT) that will return a root of the funct...

    Write a MATLAB function newtonRaphson(fx, x0, sigfig, maxIT) that will return a root of the function f(x) near x=x0 using the Newton-Raphson method, where sigfig is the accuracy of the solution in terms of significant figures, and maxIT is the maximum number of iterations allowed. In addition to the root (xr), the function newtonRaphson is expected to return the number of iterations and an error code (errorCode). As such, the first line of the function m file newtonRaphson.m must read...

  • X Solution.pdf x Solved Problems x 1 * Chapter%206.pdf 18-02-ME-GE301 " Univery macaron ROBLEM 6.11 (a)...

    X Solution.pdf x Solved Problems x 1 * Chapter%206.pdf 18-02-ME-GE301 " Univery macaron ROBLEM 6.11 (a) Apply the Newton-Raphson method to the function f(x) = tanh(x2 – 9) to evaluate its known real root at x = 3. Use an initial guess of Xo = 3.2 and take a minimum of three iterations. (b) Did the method exhibit convergence onto its real root? Sketch the plot with the results for each iteration labeled. Alla y PROBLEM 6.11 (a) Apply the...

  • Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube...

    Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube root (a)1/3 of a given number a with accuracy roughly within 10-8 using x0 = a/2. Use at most 100 iterations. Explain steps by commenting on them. Use f(x) = x3 − a. Choose a = 2 + w, where w = 3 Algorithm : Newton-Raphson Iteration Input: f(x)=x3−a, x0 =a/2, tolerance 10-8, maximum number of iterations100 Output: an approximation (a)1/3 within 10-8 or...

  • clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold...

    clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold = 0.5; % this is the initial guess test = 1; % this simply ensures we have a test value to enter the loop below. %If we don't preallocate this, MATLAB will error when it trys to start the %while loop below k = 1; %this is the iteration counter. Similar to "test" we need to preallocate it %to allow the while loop to...

  • 6.5 Employ the Newton-Raphson method to determine a real root for 4x20.5 using initial guesses of...

    6.5 Employ the Newton-Raphson method to determine a real root for 4x20.5 using initial guesses of (a) 4.52 f(x) 15.5x Pick the best numerical technique, justify your choice and then use that technique to determine the root. Note that it is known that for positive initial guesses, all techniques except fixed-point iteration will eventually converge. Perform iterations until the approximate relative error falls below 2 %. If you use a bracket- ing method, use initial guesses of x 0 and...

  • Write a function named “NewtonRaphson” that implements the Newton-Raphson method. The inputs to this function are...

    Write a function named “NewtonRaphson” that implements the Newton-Raphson method. The inputs to this function are the name of the function, name of the function’s derivative function, initial guess, maximum number of iterations, and tolerance for the relative convergence error. The output is the root. Use the problem in Homework #3 to test your function.    Hw 3 that we are pulling from %Newton-Raphson method to find upward velocity of a rocket clear all; clc; u=2200; %m/s m0=160000; %kg q=2680;...

  • L. Determine the real root(s) off(x)--5xs + 14x3 + 20x2 + 10x a. Graphically on a graph paper. b....

    l. Determine the real root(s) off(x)--5xs + 14x3 + 20x2 + 10x a. Graphically on a graph paper. b. Using Bisection method c. Using False Position method to determine the root, employing initial guesses of x-2 d. Using the Newton Raphson methods to determine the root, employing initial guess to determine the root, employing initial guesses ofxn-2 and Xu-4 and Es= 18%. and r 5.0 andas answer. 1%. was this method the best for these initial guesses? Explain your xo--l...

  • MATLAB QUESTION please include function codes inputed Problem 3 Determine the root (highest positive) of: F(x)=...

    MATLAB QUESTION please include function codes inputed Problem 3 Determine the root (highest positive) of: F(x)= 0.95x.^3-5.9x.^2+10.9x-6; Note: Remember to compute the error Epsilon-a after each iteration. Use epsilon_$=0.01%. Part A Perform (hand calculation) 3 iterations of Newton's Raphson method to solve the equation. Use an initial guess of x0=3.5. Part B Write your own Matlab function to validate your results. Part C Compare the results of question 1 to the results of question 2, what is your conclusion ?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT