Question

A. Implement the False-Position (FP) method for solving nonlinear equations in one dimension. The program should be started f2. a) Use your NR code to find the positive root of the equation given below using the following points as initial guesses: x

A. Implement the False-Position (FP) method for solving nonlinear equations in one dimension. The program should be started from a script M-file. -Prompt the user to enter lower and upper guesses for the root. .Use an error tolerance of 107. Allow at most 1000 iterations The code should be fully commented and clear " 1. Use your FP and NR codes and appropriate initial guesses to find the root of the following equation between 0 and 5. Plot the root and the approximate error as a function of the iteration number for both methods, compare the performances of the methods and discuss the results o 3x3 +4x2 - 5x-9 0
2. a) Use your NR code to find the positive root of the equation given below using the following points as initial guesses: xo = 4, 0 and-1, Plot the root and the approximate error as a function of the iteration number. Report the estimated root for each case, describe the differences in the behavior depending on the initial guess and discuss the results o 8000x - 500x3+ 4000 0 b) Verify your NR code using the graphical approach.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Matlab code is given below. There is newtonRaphson method , false position method and another file to tes them.

If we compare the graphs of errors and roots against the iteration number we find that Newton method converges to the final root very fast as compared to final position

*************************false_position.m*************************

function [ E,R,r ] = false_position( f,a,b,max_iters )
%This is the function for calculation the root
%It takes in the polynomial f and calculates final root r
%Also it calculates the intermediate roots R
%and the errors in betweenFalse position False position 15 1.5 10 0.5 50 teration Newton raphson 100 50 teration Newton raphson 100 6 1.6 4 1.5 1.4 1.3

tol=1e-7;
c=a;

E=[];
R=[];
i=0;
while i<max_iters
%here this is the false position formula
c = (a f(b) - b f(a))/ (f(b) - f(a));
err=abs(f(c)-0);
%add error to vector E
E=[E err];
R=[R c]
%This loop will continue to refine values of c
%until err gets less than tol i.e. 10^-7
if err<tol
break;
end
%update c as per false position rule
if (f(c) * f(a)) < 0
b = c ;
else
a = c ;
end
i=i+1;
end

r=c;
end

***********************************NewtonRaphson.m*************************

function [E,R,r] = NewtonRaphson( F,dFdx,xi,imax )
%Newton raphson method also needs derivative of the function
%xi is the initial guess
%imax is the maximum iterations
%F is the function
%dFdx is the derivative
X=xi;
n=0;
tol=1e-7;
%Fill Errors in E and all intermediate roots in R
E=[];
R=[];
while n<imax
n=n+1;
%below is the newton raphson formula
% to update the approximate root
X=X-F(X)/dFdx(X);
R=[R X];
%calculate the error
%F(x) is the calculated value at x
% while as 0 is the true value
err=abs(F(X)-0);
E=[E err]
if err<tol
break
end

end

r=X;
end

****************************TestBoth.m******************************

%This script file tests the false position and Newton raphson
%functions

%create the polynomial as anonymous function as
f=@(x)3*x^3+4*x^2-5*x-9;

%derivative of above function
dfdx=@(x)9*x^2+8*x-5;
lower_bound=input('Enter lower bound for False position:');
upper_bound=input('Enter upper bound for False position:');
initial_guess=input('Enter initial guess for Netwon Raphson:');
max_iters=1000;

%gather the roots and errors from false position
[E,R,r]=false_position(f,lower_bound,upper_bound,max_iters);
len=length(E);
i=1:1:len;
%gather the roots and errors from Newtonraphson
[E2,R2,r2]=NewtonRaphson(f,dfdx,initial_guess,max_iters);
len2=length(E2);
j=1:1:len2;

%plot errors and roots against iteration for both methods
subplot(221)
plot(i,E);
title('False position')
xlabel('íteration')
ylabel('Error')

subplot(222)
plot(i,R);
title('False position')
xlabel('íteration')
ylabel('Root')

subplot(223)
plot(j,E2);
title('Newton raphson')
xlabel('íteration')
ylabel('Error')

subplot(224)
plot(j,R2);
title('Newton raphson')
xlabel('íteration')
ylabel('Root')

fprintf('Root by false position=%f\n',r);
fprintf('Root by Newton Raphson=%f',r2);

Add a comment
Know the answer?
Add Answer to:
A. Implement the False-Position (FP) method for solving nonlinear equations in one dimension. The...
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
  • B. Implement the Newton-Raphson (NR) method for solving nonlinear equations in one dimension. The...

    B. Implement the Newton-Raphson (NR) method for solving nonlinear equations in one dimension. The program should be started from a script M-file. Prompt the user to enter an initial guess for the root. -Use an error tolerance of 107, -Allow at most 1000 iterations. .The code should be fully commented and clear 2. a) Use your NR code to find the positive root of the equation given below using the following points as initial guesses: xo = 4, 0 and-1...

  • 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...

  • Need solution for question 5.6 using python? tation to within e, 5.11 Determine the real root...

    Need solution for question 5.6 using python? tation to within e, 5.11 Determine the real root of x 80: (a) analytically and (b) with the false-position method to within e, = 2.5%. Use initial guesses of 2.0 and 5.0. Compute the estimated error Ea and the true error after each 1.0% teration 5.2 Determine the real root of (x) 5r - 5x2 + 6r -2 (a) Graphically (b) Using bisection to locate the root. Employ initial guesses of 5.12 Given...

  • Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point...

    Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point method and use your code to find the root of the following equation using an initial guess of 3 and a stopping criterion of 0.001%; f(x) e -4x For Fixed-Point, you do not have to code Matlab to take the derivatives of the function and check the g'(x). You can do that step by hand, and then show me your hand cal ulations to...

  • In MATLAB please Consider the nonlinear function: y = f(x) = x3 cos x a. Plot...

    In MATLAB please Consider the nonlinear function: y = f(x) = x3 cos x a. Plot y as a function of x as x is varied between -67 and 67. In this plot mark all the locations of x where y = 0. Make sure to get all the roots in this range. You may need to zoom in to some areas of the plot. These locations are some of the roots of the above equation. b. Use the fzero...

  • Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you...

    Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you 5. In this problem we will investigate using the Secant Method to approximate a root of a function f(r). The Secant Method is an iterative approach that begins with initial guesses , and r2. Then, for n > 3, the Secant Method generates approximations of a root of f(z) as In-1-In-2 n=En-1-f (x,-1) f(Fn-1)-f(-2) any iteration, the absolute error in the approximation can be...

  • Problem Two: (Based on Chapra, Problems 12.9 Consider the simultaneous nonlinear equations: 2-5-y y+i- 1. Plot...

    Problem Two: (Based on Chapra, Problems 12.9 Consider the simultaneous nonlinear equations: 2-5-y y+i- 1. Plot the equations and identify the solution graphically. Page 1 of 2 2. Solve the system of equations using successive substitution, starting with the initial guess xo-y-1.5. Show two complete iterations. Evaluate &s for the second iteration. 3. Redo Part 2 using Newton-Raphson method . Automate the solutions in Parts 2 and 3 using MATLAB scripts 5. Solve the system of nonlinear equations by calling...

  • 3. A nonlinear system: In class we learned how to use Taylor expansion up to the 1* order term to...

    3. A nonlinear system: In class we learned how to use Taylor expansion up to the 1* order term to solve a system of two non-linear equations; u(x.y)- 0 and v(x.y)-0. This method is also called Newton-Raphson method. (a) As we did in lecture, expand u and v in Taylor series up to the 1st order and obtain the iterative formulas of the method. (In the exam you should have this ready in your formula sheet). 1.2) as an initial...

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

  • . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The ...

    . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The derivative of the function can be approximately evaluated using finite-difference method. Consider the Forward and Centered finite-difference formulas Forward Finite-Difference Centered Finite-Difference 2h It is worthwhile to mention that modified secant method was derived based on the forward finite- difference formula. Develop a MATLAB functions that has the following syntax function [root,fx,ea,iter]-modnetraph (func,x0,h,es,maxit,sethod, varargin) % modnevtraph: root location zeroes of nonlinear equation f (x)...

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