Thursday, February 22, 2024

x̄ - > The Newton-Raphson method

 The Newton-Raphson method, also known simply as Newton's method, is an iterative numerical technique used to find the root of a real-valued function. It's particularly useful for finding roots of non-linear equations. The method was independently discovered by Isaac Newton and Joseph Raphson.


Given a function \( f(x) \) and an initial guess \( x_0 \) for the root, the Newton-Raphson method iteratively refines the guess using the formula:


\[ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} \]


Where:

- \( x_{n+1} \) is the next approximation of the root.

- \( x_n \) is the current approximation of the root.

- \( f(x_n) \) is the value of the function at the current approximation.

- \( f'(x_n) \) is the derivative of the function at the current approximation.


The process continues until the desired level of accuracy is achieved or until a maximum number of iterations is reached.


Here's a step-by-step outline of the Newton-Raphson method:


1. Choose an initial guess \( x_0 \) for the root.

2. Compute \( f(x_0) \) and \( f'(x_0) \).

3. Update the guess for the root using the formula above: \( x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} \).

4. Repeat steps 2 and 3 until the desired level of accuracy is achieved or until reaching a predefined maximum number of iterations.


It's important to note that Newton's method may not always converge or may converge to a local minimum or maximum instead of a root if certain conditions are not met, such as choosing a poor initial guess or when the function behaves irregularly near the root.


Despite its limitations, Newton's method is widely used due to its rapid convergence for well-behaved functions and its simplicity of implementation. Additionally, it can be extended to find multiple roots or roots of systems of equations.


Sure, let's walk through an example of applying the Newton-Raphson method to find the root of a function. 


Let's say we want to find the root of the function \( f(x) = x^3 - 2x^2 - 5 \).


First, we need to find the derivative of \( f(x) \) which is \( f'(x) = 3x^2 - 4x \).


Now, let's choose an initial guess for the root. Let's say \( x_0 = 3 \).


We will iterate using the Newton-Raphson formula:


\[ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} \]


Here's the calculation for the first iteration:


\[ f(3) = (3)^3 - 2(3)^2 - 5 = 27 - 18 - 5 = 4 \]

\[ f'(3) = 3(3)^2 - 4(3) = 27 - 12 = 15 \]


Now, applying the formula:


\[ x_1 = 3 - \frac{4}{15} \approx 2.733 \]


We continue this process until we reach the desired level of accuracy or until a maximum number of iterations is reached.


Let's proceed with one more iteration:


\[ f(2.733) = (2.733)^3 - 2(2.733)^2 - 5 \approx -0.158 \]

\[ f'(2.733) = 3(2.733)^2 - 4(2.733) \approx 7.477 \]


Now, applying the formula:


\[ x_2 = 2.733 - \frac{-0.158}{7.477} \approx 2.683 \]


We can continue this process until we reach the desired level of accuracy. Typically, you'd continue until \( |x_{n+1} - x_n| \) is smaller than a predefined tolerance level.


In this example, we can see that after just two iterations, we've already approximated the root to be around \( x \approx 2.683 \). We can continue iterating to get a more precise result if needed.


The Newton-Raphson method, also known as Newton's method, is an iterative root-finding algorithm used to approximate solutions of equations. In R, you can implement the Newton-Raphson method for finding roots of a function using a loop or recursive function. Here are five examples demonstrating the Newton-Raphson method in R:


1. Finding square root using Newton-Raphson method:


PHONES CATEGORY


```R

newton_sqrt <- function(x, guess = 1, tolerance = 1e-6) {

  while (abs(guess^2 - x) > tolerance) {

    guess <- (guess + x / guess) / 2

  }

  return(guess)

}


# Example usage:

sqrt_value <- newton_sqrt(25)

print(sqrt_value)

```


2. Finding cube root using Newton-Raphson method:


```R

newton_cbrt <- function(x, guess = 1, tolerance = 1e-6) {

  while (abs(guess^3 - x) > tolerance) {

    guess <- (2 * guess + x / guess^2) / 3

  }

  return(guess)

}


# Example usage:

cbrt_value <- newton_cbrt(27)

print(cbrt_value)

```


3. Finding a root of a polynomial equation:


```R

# Define the polynomial function

polynomial <- function(x) {

  return(x^3 - 6*x^2 + 11*x - 6)

}


# Derivative of the polynomial

polynomial_derivative <- function(x) {

  return(3*x^2 - 12*x + 11)

}


newton_root <- function(func, deriv, guess = 1, tolerance = 1e-6) {

  while (abs(func(guess)) > tolerance) {

    guess <- guess - func(guess) / deriv(guess)

  }

  return(guess)

}


# Example usage:

root_value <- newton_root(polynomial, polynomial_derivative, guess = 2)

print(root_value)

```


4. **Finding a root of a trigonometric equation:**


```R

# Define the trigonometric function

trig_function <- function(x) {

  return(sin(x) - 0.5)

}


# Derivative of the trigonometric function

trig_derivative <- function(x) {

  return(cos(x))

}


# Example usage:

root_value <- newton_root(trig_function, trig_derivative, guess = 1)

print(root_value)

```


5. **Finding a root of a logarithmic equation:**


```R

# Define the logarithmic function

log_function <- function(x) {

  return(log(x) - 2)

}


# Derivative of the logarithmic function

log_derivative <- function(x) {

  return(1/x)

}


# Example usage:

root_value <- newton_root(log_function, log_derivative, guess = 3)

print(root_value)

```


These examples demonstrate how to use the Newton-Raphson method to find roots of various types of equations in R programming.

No comments:

Meet the Authors
Zacharia Maganga’s blog features multiple contributors with clear activity status.
Active ✔
πŸ§‘‍πŸ’»
Zacharia Maganga
Lead Author
Active ✔
πŸ‘©‍πŸ’»
Linda Bahati
Co‑Author
Active ✔
πŸ‘¨‍πŸ’»
Jefferson Mwangolo
Co‑Author
Inactive ✖
πŸ‘©‍πŸŽ“
Florence Wavinya
Guest Author
Inactive ✖
πŸ‘©‍πŸŽ“
Esther Njeri
Guest Author
Inactive ✖
πŸ‘©‍πŸŽ“
Clemence Mwangolo
Guest Author

x̄ - > Bloomberg BS Model - King James Rodriguez Brazil 2014

Bloomberg BS Model - King James Rodriguez Brazil 2014 πŸ”Š Read ⏸ Pause ▶ Resume ⏹ Stop ⚽ The Silent Kin...

Labels

Data (3) Infographics (3) Mathematics (3) Sociology (3) Algebraic structure (2) Environment (2) Machine Learning (2) Sociology of Religion and Sexuality (2) kuku (2) #Mbele na Biz (1) #StopTheSpread (1) #stillamother #wantedchoosenplanned #bereavedmothersday #mothersday (1) #university#ai#mathematics#innovation#education#education #research#elearning #edtech (1) ( Migai Winter 2011) (1) 8-4-4 (1) AI Bubble (1) Accrual Accounting (1) Agriculture (1) Algebra (1) Algorithms (1) Amusement of mathematics (1) Analysis GDP VS employment growth (1) Analysis report (1) Animal Health (1) Applied AI Lab (1) Arithmetic operations (1) Black-Scholes (1) Bleu Ranger FC (1) Blockchain (1) CATS (1) CBC (1) Capital markets (1) Cash Accounting (1) Cauchy integral theorem (1) Coding theory. (1) Computer Science (1) Computer vision (1) Creative Commons (1) Cryptocurrency (1) Cryptography (1) Currencies (1) DISC (1) Data Analysis (1) Data Science (1) Decision-Making (1) Differential Equations (1) Economic Indicators (1) Economics (1) Education (1) Experimental design and sampling (1) Financial Data (1) Financial markets (1) Finite fields (1) Fractals (1) Free MCBoot (1) Funds (1) Future stock price (1) Galois fields (1) Game (1) Grants (1) Health (1) Hedging my bet (1) Holormophic (1) IS–LM (1) Indices (1) Infinite (1) Investment (1) KCSE (1) KJSE (1) Kapital Inteligence (1) Kenya education (1) Latex (1) Law (1) Limit (1) Logic (1) MBTI (1) Market Analysis. (1) Market pulse (1) Mathematical insights (1) Moby dick; ot The Whale (1) Montecarlo simulation (1) Motorcycle Taxi Rides (1) Mural (1) Nature Shape (1) Observed paterns (1) Olympiad (1) Open PS2 Loader (1) Outta Pharaoh hand (1) Physics (1) Predictions (1) Programing (1) Proof (1) Python Code (1) Quiz (1) Quotation (1) R programming (1) RAG (1) RL (1) Remove Duplicate Rows (1) Remove Rows with Missing Values (1) Replace Missing Values with Another Value (1) Risk Management (1) Safety (1) Science (1) Scientific method (1) Semantics (1) Statistical Modelling (1) Stochastic (1) Stock Markets (1) Stock price dynamics (1) Stock-Price (1) Stocks (1) Survey (1) Sustainable Agriculture (1) Symbols (1) Syntax (1) Taroch Coalition (1) The Nature of Mathematics (1) The safe way of science (1) Travel (1) Troubleshoting (1) Tsavo National park (1) Volatility (1) World time (1) Youtube Videos (1) analysis (1) and Belbin Insights (1) competency-based curriculum (1) conformal maps. (1) decisions (1) over-the-counter (OTC) markets (1) pedagogy (1) pi (1) power series (1) residues (1) stock exchange (1) uplifted (1)

Followers