Skip to content

YlmzCmlttn

Cemalettin Yılmaz Blog

Menu
  • Home
  • About Me
  • Projects
    • Iot-AR
    • Magnifi-AR
    • Smarthome-IOS
    • Others
  • Categories
    • Articles
    • Augmented Reality
    • Capture The Flag
      • Google CTF
        • 2018
    • Embedded Systems
    • IoT
    • Logisim
    • My Essays
    • Nvidia Jetson
      • Jetson TX1
    • Operating Systems
      • Kali
      • Raspbian
      • Ubuntu
    • Personal
    • Programming
      • Arduino
      • C
      • C#
      • Css
      • Html
      • Js
      • Matlab
      • Node.js
      • Python
      • Swift
      • VHDL
    • Projects
      • Embedded Systems
      • Electric
      • IoT
      • IoT-AR
      • Logisim
      • Magnifi-AR
      • Pose Estimation
    • Raspberry Pi
    • Xilinx
    • Others
Menu

Finding Root of a Number by Newton-Raphson Method | Matlab Examples

Posted on November 25, 2018February 20, 2019 by Yılmaz Cemalettin

Matlab Tutorials | Examples

Practice 3:

Finding Root of a Number by Newton-Raphson Method

In numerical analysis, Newton’s method (also known as the Newton– Raphson method), named after Isaac Newton and Joseph Raphson, is perhaps the best known method for finding successively better approximations to the zeroes (or roots) of a real-valued function. Newton’s method can often converge remarkably quickly; especially if the iteration begins “sufficiently near” the desired root.

Given a function ƒ(x) and its derivative ƒ ‘(x), we begin with a first guess x0. A better approximation x1 is:

This iterative solution can be used in finding the root of a number. Take f(x) and f ′(x)

as:


For example, if a=400, this iteration should give x approximately as 20.

Write a MatLab code that will do the following:

  1. Get a number of iterations, the initial guess, and ε from the user.
  2. Find the root by using the Newton-Raphson method.
  3. Find the exact root using the sqrt() function.
  4. If the difference between the real root (found in step 3) and the root found by

    Newton-Raphson method is smaller than ε, display the root; otherwise, display “the root could not be found”.

Use only scalar variables; no vectors or matrices. ε (epsilon) is the sensitivity, which is used to test the accuracy of the solution.

 

Solution:

Matlab Code
MATLAB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
clc
clear
a = input('Enter a: ');%Inputs
i = input('Enter number of iterations: ');
x = input('Enter initial guess: ');
e = input('Enter epsilon: ');
for n=1:i
    x = x - (((x^2) - a) / (2*x)); %iterations
end
error=abs(x-sqrt(a)); %difference between previous approximation and new approximation in newtorn rapson method.
if error<e % checking error
    fprintf('The root of the function is at %g Error is %g',x,error);
else
    fprintf('Root can not be found error is %g',error);
end

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

My Motto

“Learn to share, Share to learn”

LinkedIn Badge

Cemalettin Yılmaz

Ads

Archives

Categories

  • Articles (1)
  • Augmented Reality (3)
  • Capture The Flag (23)
    • Google CTF (22)
      • 2018 (13)
      • 2019 (9)
    • PicoCTF (1)
      • 2019 (1)
  • Embedded Systems (3)
  • IoT (3)
  • Logisim (1)
  • My Essays (3)
  • Nvidia Jetson (5)
    • Xavier (5)
  • Operating Systems (24)
    • Kali (3)
    • Raspbian (2)
    • Ubuntu (21)
  • Others (1)
  • Personal (1)
  • Programming (44)
    • Arduino (4)
    • C (10)
    • C# (4)
    • C++ (5)
    • Css (1)
    • CUDA (6)
    • Html (1)
    • Js (2)
    • Libraries (5)
      • OpenCV (3)
      • OpenGL (2)
    • Matlab (14)
    • Node.js (5)
    • Python (6)
    • Swift (3)
  • Programs (4)
    • Tools (4)
  • Projects (21)
    • Books Solutions (8)
    • Electric (2)
    • Embedded Systems (2)
    • Energy Harvesting (1)
    • IoT (2)
    • IoT-AR (1)
    • Logisim (1)
    • Magnifi-AR (3)
    • Pose Estimation (3)
    • Smarthome-Ios (1)
  • Raspberry Pi (3)
  • Uncategorized (2)
  • YZlib (1)

Recent Posts

  • atof stof stod problems with local floating point separator in C/C++
  • Pico CTF 2019 Answers
  • YZlib: Personal C++ Library
  • Drive to target | Google CTF 2019
  • FriendSpaceBookPlusAllAccessRedPremium | Google CTF 2019

Recent Comments

  • AbaShelha on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Peter on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on 16-Bit CPU on Logisim
  • Jenny on 16-Bit CPU on Logisim
  • MOON on 16-Bit CPU on Logisim
  • anti on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • hunkerjr on STOP GAN | Google CTF 2019
  • Shaq on 16-Bit CPU on Logisim
  • NURUL AFIQAH MOHD HASBULLAH on 16-Bit CPU on Logisim

Linkedln

© 2022 YlmzCmlttn | Powered by Superbs Personal Blog theme