Given: $ f(x) = x^2-10x+9$, find the roots using the secant method.
Computation:
1. We choose two points for $x_{-1}$ and $x_{0}$.
2. Solve for the next points using the formula: \[ x_n = x_{n-1} - f(x_{n-1}) \frac{x_{n-1}-x_{n-2}}{f(x_{n-1})-f(x_{n-1})} \]
This formula is derived from getting the slope of the secant lines through the points $(x_n,f(x_n))$, $(x_{n-1},f(x_{n-1}))$ and $(x_{n-2},f(x_{n-2}))$.
\[ \frac{f(x_n) - f(x_{n-1})}{x_n - x_{n-1}} = \frac{f(x_{n-1}) - f(x_{n-2})}{x_{n-1} - x_{n-2}} \]
Since $f(x_n)=0$, then
\[ \frac{0 - f(x_{n-1})}{x_n - x_{n-1}} = \frac{f(x_{n-1}) - f(x_{n-2})}{x_{n-1} - x_{n-2}} \]
Solve for $x_n.$
\[ \begin{split}
- f(x_{n-1})(x_{n-1} - x_{n-2}) &= (x_n - x_{n-1})( f(x_{n-1}) - f(x_{n-2})) \\
\frac{- f(x_{n-1})(x_{n-1} - x_{n-2})}{ f(x_{n-1}) - f(x_{n-2})} &= x_n - x_{n-1} \\
x_{n-1} - \frac{ f(x_{n-1})(x_{n-1} - x_{n-2})}{ f(x_{n-1}) - f(x_{n-2})} &= x_n \\
x_n &= x_{n-1} - \frac{ f(x_{n-1})(x_{n-1} - x_{n-2})}{ f(x_{n-1}) - f(x_{n-2})} \end{split}\]
3. Continue to iterate until $f(x) = 0$ or we've applied the stopping rules.
This is my answer.
So far in excel it works. How about applying these methods in Visual Basic? Will it work? What can be my possible problems?
No comments:
Post a Comment