Question

In: Advanced Math

Write a program to compute the root of the function f(x) = x3 + 2 x2...

Write a program to compute the root of the function f(x) = x3 + 2 x2 + 10 x - 20 by Newton method ( x0 =2 ). Stop computation when the successive values differ by not more than 0.5 * 10-5 . Evaluate f(x) and f '(x) using nested multiplication. The output should contain:

(1) A table showing at each step the value of the root , the value of the function,and the error based upon successive approximation values and percentage error for each method.

(2) A plot showing the variation of percentage error with iteration number for each method on the same graph so as to compare the method.

Solutions

Expert Solution

We have solved the given problem using MATLAB code. (Code attached).

MATLAB code:

function newton()

fprintf('\n');
prompt1='Enter the Initial guess x0: ';
prompt2='Enter the accuracy percentage: ';
x0= input(prompt1);
tol= input(prompt2);
  
f = @(x) x.^3+2*x.^2+10*x-20;
dfdx= @(x) 3*x.^2+4*x+10;
error=1e10;
x_old=x0;
A(1,:)=[0 x_old f(x_old) 0 0];
  
fprintf('\n\n\nIteration Root Function Value Absolute error Percentage error\n');
fprintf('--------- ----------- ---------------- ---------------- -----------------\n');
fprintf('%3d %12.8f %12.8f\n',A(1,1),A(1,2),A(1,3));
n=1;
  
while error>tol
n=n+1;
x_new=x_old-f(x_old)/dfdx(x_old);
error=abs(x_new-x_old);
A(n,:)=[n-1 x_new f(x_new) abs(x_new-x_old) abs(x_new-x_old)/x_old];
fprintf('%3d %12.8f %12.8f %12.8f %12.8f\n',A(n,1),A(n,2),A(n,3),A(n,4),A(n,5));
x_old=x_new;
end
fprintf('\n\n');
  
figure(1)
plot(A(2:end,1),A(2:end,5))
xlabel('Iterations')
ylabel('Percentage error')
title('Iterations vs Percentage error graph')
end


Related Solutions

3. Given is the function f : Df → R with F(x1, x2, x3) = x...
3. Given is the function f : Df → R with F(x1, x2, x3) = x 2 1 + 2x 2 2 + x 3 3 + x1 x3 − x2 + x2 √ x3 . (a) Determine the gradient of function F at the point x 0 = (x 0 1 , x0 2 , x0 3 ) = (8, 2, 4). (b) Determine the directional derivative of function F at the point x 0 in the direction given...
Consider the function f(x)= x3 x2 − 1 Express the domain of the function in interval...
Consider the function f(x)= x3 x2 − 1 Express the domain of the function in interval notation: Find the y-intercept: y=   . Find all the x-intercepts (enter your answer as a comma-separated list): x=   . On which intervals is the function positive?   On which intervals is the function negative?   Does f have any symmetries? f is even;f is odd;     f is periodic;None of the above. Find all the asymptotes of f (enter your answers as equations): Vertical asymptote (left):   ; Vertical...
Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2...
Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2 +3x−7 Calculate the accuracy of the solution to 1 × 10−10. Find the number of iterations required to achieve this accuracy. Compute the root of the equation with the bisection method. Your program should output the following lines: • Bisection Method: Method converged to root X after Y iterations with a relative error of Z.
(1) z=ln(x^2+y^2), y=e^x. find ∂z/∂x and dz/dx. (2) f(x1, x2, x3) = x1^2*x2+3sqrt(x3), x1 = sqrt(x3),...
(1) z=ln(x^2+y^2), y=e^x. find ∂z/∂x and dz/dx. (2) f(x1, x2, x3) = x1^2*x2+3sqrt(x3), x1 = sqrt(x3), x2 = lnx3. find ∂f/∂x3, and df/dx3.
2. For the function : f(x) = x2 − 30x − 2 a) State where f...
2. For the function : f(x) = x2 − 30x − 2 a) State where f is increasing and where f is decreasing b) Identify any local maximum or local minimum values. c) Describe where f is concave up or concave down d) Identify any points of inflection (in coordinate form) 3. For the function f (x)= x4 − 50 2 a) Find the intervals where f is increasing and where f is decreasing. b) Find any local extrema and...
Let X = ( X1, X2, X3, ,,,, Xn ) is iid, f(x, a, b) =...
Let X = ( X1, X2, X3, ,,,, Xn ) is iid, f(x, a, b) = 1/ab * (x/a)^{(1-b)/b} 0 <= x <= a ,,,,, b < 1 then, find a two dimensional sufficient statistic for (a, b)
1. The function f(x, y) = ln(x3 + 2) / (y2 + 3) (this function is...
1. The function f(x, y) = ln(x3 + 2) / (y2 + 3) (this function is of a fraction format) : a. has a stationary point at (1, 0) b. has a stationary point at (0, 0) c. has a stationary point at (0, 1) d. has no stationary points 2. Which of the following functions don’t have unit elasticity at P = 6? a. Demand: Qd = 24 - 2 P b. Demand: Qd = 10/P c. Demand: log...
Let X1, X2, X3 be continuous random variables with joint pdf f(X1, X2, X3)= 2 if...
Let X1, X2, X3 be continuous random variables with joint pdf f(X1, X2, X3)= 2 if 1<X1<2 -1<X2<0 -X2-1<X3<0                         0 otherwise Find Cov(X2, X3)
The prices of inputs (x1,x2,x3,x4) are (4,1,3,2): (a) If the production function is given by f(x3,x4)...
The prices of inputs (x1,x2,x3,x4) are (4,1,3,2): (a) If the production function is given by f(x3,x4) =min⁡{x1+x2,x3+x4} what is the minimum cost of producing one unit of output? (b) If the production function is given by f(x3,x4)=x1+x2 +min⁡{x3+x4} what is the minimum cost of producing one unit of output?
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2...
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2 + 10x -20, with x_0 = 2, and x_1 = 1.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT