0

Could someone show the procedure for the following two numerical method problems:

  1. Solve an equation $f(x)=x^2-e^x+2=0$ with precision up to $10^{-4}$ using the secant method.

  2. Using the tangent method, find one positive root of equation $\cos x=x^2-2$, with precision less than $10^{-4}.$ Localize the solution on an interval of length at least $0.5.$

user300045
  • 3,449

1 Answers1

3

$1$: Find root using secant method

$$ f(x) = x^{2} - e^{x} + 2 $$

plot

The root is at $x= 1.3190736768573654$


Secant method

MathWorld: Secant Method; Wikipedia: Secant method

Method

  1. Pick a value for $x_{0}$

  2. Pick a value for $x_{1}$

  3. Iterate using $$ x_{n} = x_{n-1} - f\left(x_{n-1}\right) \frac{x_{n-1} - x_{n-2}}{f\left(x_{n-1}\right) - f\left(x_{n-2})\right)} $$

Example

Set $x_{0}=1$, $x_{1} = 1.5$.

$$ \begin{align} x_{2} &= \color{blue}{1}.2743613145286912 \\ x_{3} &= \color{blue}{1.31}28043183949625 \\ x_{4} &= \color{blue}{1.319}2956677042882 \\ x_{5} &= \color{blue}{1.31907}25774798735 \\\hline x_{6} &= \color{blue}{1.319073676}6646676 \\ \end{align} $$



$2$: Find root using Newton's method

$$ f(x) = x^{2} - 2 - \cos x $$

other root

The roots are at $x= \pm1.4546189292081113$


Tangent method

MathWorld: Newton's Method, Wikipedia: Newton's method

Method

  1. Pick a value for $x_{0}$

  2. Iterate using $$ x_{n} = x_{n-1} - \frac{f\left(x_{n-1}\right)} {f'\left(x_{n-1}\right)} $$

Example

Set $x_{0}=1$. The derivative is $$ f'(x)= 2x+\sin x $$ The sequence of roots is $$ \begin{align} x_{1} &= \color{blue}{1}.5420791956361556951 \\ x_{2} &= \color{blue}{1.45}65461937663345119 \\ x_{3} &= \color{blue}{1.45461}99345022899466 \\ x_{4} &= \color{blue}{1.454618929208}3852544 \\\hline x_{5} &= \color{blue}{1.454618929208111}2788 \\ \end{align} $$

dantopa
  • 10,342
  • how would you write your algorithm to stop at certain precision? – Anonymous Jun 18 '17 at 01:30
  • ok don't worry I've just realized... wouldn't hurt to hear your thoughts though. – Anonymous Jun 18 '17 at 01:32
  • 1
    @Anonymous: the algorithm is converging. You would stop it with an accuracy goal, $\lvert x_{n+1} - x_{n} \rvert < 0.001$, for both cases. – dantopa Jun 18 '17 at 01:37
  • 1
    yeah pretty much what I though $|x_n-x_{n-1}|< \epsilon$ although sometimes one should be careful with looping like that with floating points. – Anonymous Jun 18 '17 at 01:38
  • If you want more safety, check the above accuracy goal for two steps and also that the reduction in value, $f(x_n)/f(x_0)$, is large enough. Which here is not necessary. – Lutz Lehmann Jun 18 '17 at 06:02
  • It is reasonable to find the range og root first. for x^2-e^x+2 if x=1 then e^x=2.718.. and x^2+2=3 so we can start with x=1. For Cos x =x^2-2 if Cos x=0 we get x = 3.14../2 =1.57.. and with x^2-2=0 we get x =2^.5 =1.4142.. so it is reasonable to take x = 1.5 which is the average for start. – sirous Jun 18 '17 at 08:48