Sie sind auf Seite 1von 4

Rochester Institute of

Technology

EEEE346 Advanced
Programming Technical
Memorandum
From:
Partner:
Performed:
Subject:

Project #1: Newton-Raphson Method

-------------------------------------------------------------------------------------------------------------------Abstract:
In this project we implemented the Newton-Raphson method using C++ to find
approximations of the roots of functions. The Newton-Raphson method was implemented using
both recursive and iterative functions. Also, the time it took for the recursive function to execute
was compared to the time it took for the iterative function to execute. The Newton-Raphson
method was then applied to a non-linear circuit to calculate the voltage of a diode in the circuit.
All of these objectives were accomplished using a C++ editor.
Theory:
The Newton-Raphson method is a numerical analysis method for finding approximations
for roots of functions. The equation of a root found using this method is defined as:
x n+1=x n

f ( xn )
f ' ( xn )

The Newton-Raphson method is recursive in that it calls itself repeatedly in order to make its
guess closer to being correct. We are told to analyze a non-linear circuit using this method in

order to find the voltage across the diode inside the circuit. The current-voltage equation is given
as:
I =I s

VD
nV T

In order to analyze the circuit, Kirchoffs Current Law (KCL) is implemented along with the
diodes current-voltage equation. KCL states that all current entering the node equals all current
leaving the node. The combined equation is defined as:

VD

V V D
fCircuit = s
I s e nV 1
R
T

These equations were implemented using C++ as well as the functions previously created for the
Newton-Raphson method.
Results and Discussion:
The three functions;

x 2+3 x1 , sin ( x) , e x /22 x

were implemented in a source


x

file along with their first derivatives 2 x +3 , cos ( x) ,


the
which
file.

seen
and 2.

Figure 1 Recursive function

1 2
(e 4) . These were called in
2
recursive and
iterative functions
were written in a
separate source
Examples of the
iterative and
recursive
functions can be
below in figures 1

Figure 2 Iterative function

The original function is represented by fa and the derivative is represented by fa_prime. For
the recursive example the function calls itself repeatedly until the variables newguess and
guess are equal. For the iterative example the function enters the while loop and continues to
execute the code inside until the variables newguess and guess are equal. The pointer that is
seen in this example points to a variable in the main function. Its purpose is to count the number
of times the function iterates inside of the while loop. Both the resulting intercept of the function
and the number of iterations are printed. The time it takes for the recursive function and the
iterative function to execute was measured. Both functions were placed inside a for loop and
called 100 times. The iterative function was faster by 0.00843ms after it was run 100 times.
This shows the concept that iteration is almost always faster than recursion. A recursive function
was then applied to the circuit analysis problem. The previously stated fCircuit equation was

[ ]
VD

Is
1
nV
called along with its derivative R n V e
T

. These equations were called within a

recursive function like the one in figure 1. The individual variables were input by the user while
the program was running. The diode voltage was found to be 0.700377volts when the given
I
values R=1000, s =2.6E-15, n=1.0, VT=26.0E-3, and Vs=2.0.
Conclusion:
The object of this project was to use the Newton-Raphson method to find the roots of
functions as well as the voltage of a diode in a given non-linear circuit. The assignment was
broken up into separate source and header files that were all included in the main function. It
wasnt surprising that the recursive method was slower than the iterative method. This project
also showed that its possible to alter any recursive function into an iterative function. It was
also observed that the more iterations that were required, the farther your guess was from the
actual value. The outcome achieved from the newtonRecursiveCircuit function using the given

input values matched the approximation given of ~.7V. We feel the theory behind the analysis
matched the results observed in the experiment.

Das könnte Ihnen auch gefallen