Question
can some one edit this code
p(1)=0.4
p(2)=0.5
e=0.00001
*secant metod
>> syms x; f=(1/x) -2; e=input(Enter the epsilon: \n); p(1)=input(Enter xo(1st guess) : ); p(2)=input(Enter x1(2nd guess
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The problem occured with the function f. MATLAB took f to be an array inside the while loop rather than as a function, hence this happened. The resolved code is given below:

1 syms x; 2 f = @(x) 1./x.-2 3 e = 0.00001 4 p(1) = 0.4 5 p (2) = 0.45 6 i = 3 7 Error = 1 8 while Error>=e f(p(i-1))-f(p(i-2

Also note that as 0.5 is the answer, and you are checking from i = 3, hence in the first iteration p(i-1) remains the same and zero division error occurs in the next iteration. Hence try p(2) = 0.45.

Add a comment
Know the answer?
Add Answer to:
can some one edit this code p(1)=0.4 p(2)=0.5 e=0.00001 *secant metod >> syms x; f=(1/x) -2;...
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
  • Matlab Regula Falsi Method A zero of f(x) = x^2 -4x-12.2 is known to exist on...

    Matlab Regula Falsi Method A zero of f(x) = x^2 -4x-12.2 is known to exist on the interval [1.2 , 2.2 , 3.2,...9.2] and respective right endpoints x1 =[2.2 ,3.2, 4.2....10.2], find the sub-interval in which the zero exists. Set the left endpoint of this sub-interval =a and the right endpoint=b With tolerance of 10^-9, use the Regular Falsi method to compute the root of (f) in [a,b] User input is required at ##### CONTENTS Close Courses LMS Integration Documentation...

  • in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge wh...

    in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge when using Function 4.3.1? Is the root obtained the one that is closest to that guess? )xo = 1.5, (b) x0 = 2, (c) x.-3.2, (d) xo = 4, (e) xo = 5, (f) xo = 27. Function 4.3.1 (newton) Newton's method...

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

  • Use the Newton-Raphson method to find the root of f(x) = e-*(6 - 2x) - 1...

    Use the Newton-Raphson method to find the root of f(x) = e-*(6 - 2x) - 1 Use an initial guess of xo = 1.2 and perform 3 iterations. For the N-R method: Xi+1 = x; - f(x;) f'(x;)

  • The first two parts should be solved by Matlab. This is from an intro to Numerical...

    The first two parts should be solved by Matlab. This is from an intro to Numerical Analysis Class and I have provided the Alog 3.2 in below. Please write the whole codes for me. Alog3.2 % NEWTONS INTERPOLATORY DIVIDED-DIFFERENCE FORMULA ALGORITHM 3.2 % To obtain the divided-difference coefficients of the % interpolatory polynomial P on the (n+1) distinct numbers x(0), % x(1), ..., x(n) for the function f: % INPUT: numbers x(0), x(1), ..., x(n); values f(x(0)), f(x(1)), % ...,...

  • Please do this in Matlab. Not sure if you need this code: e cofunction [x, er,...

    Please do this in Matlab. Not sure if you need this code: e cofunction [x, er, n] = FixedPoint(g, x1, maxtol, maxitr) if nargin < 4, maxitr = 25; end if nargin < 3, maxtol = 1e-3; end k = 0 ;    er = 1; x = x1;    while er >= maxtol && k < maxitr k=k+1; xold = x; x=g(x); er=abs((x-xold)/x); fprintf('iter = %i, x = %e, er = %e ', k,x,er); end n=k; if n ==...

  • (5 po)A p ia we n prie mer ae 2 7. . 1 1 do aors...

    (5 po)A p ia we n prie mer ae 2 7. . 1 1 do aors a d tr e Te Tale the w o md d the t w 2 Fi the wing s Hof te 's i a wde th itaprie For ele, ,the s tpa-2s Th e--2 Therk 2 2 ATLAB d s aw whether the er p le tapr ) M U MATLAB t ces te sod-) fti to dt wtr d y ) ( pot)...

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

  • I need someone to fix my C Program Code Firstly I will post the Q and...

    I need someone to fix my C Program Code Firstly I will post the Q and the input and the outputs Then the code Secondly the code =================================== #include <stdio.h> #include <math.h> int main() {    double a,b,c,d,l,x,x_0,x_1,x_mid,p_x,p_0,p_1,p_mid,E=1e-6; int i1,i2;          printf("Enter a,b,c,d of ax^3+bx^2+cx+d=0: "); scanf("%lf%lf%lf%lf",&a,&b,&c,&d); x_0=-50;x_1=-50;x=-50;p_0=a*(pow(x_0,3))+b*(pow(x_0,2))+c*x_0+d;i1=0;i2=0; do{        p_x=a*x*x*x+b*x*x+c*x+d;        l=p_x*p_0;        if(l<0){        x_1=x;}        i1=i1+1;x++;}        while(fabs(p_x)>=E && x<50);           if(fabs(p_x)<E){    printf("the polynominal has root...

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

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