Numerical Analysis HW 1
Numerical Analysis HW 1
Numerical Analysis HW 1
Problem 1:
In this problem we need to find the pressure drop in a sector of a pipe, essentially all of the variables in this problem are
given besides the friction factor but we can calculate this with the implicit function that is the Colebrook equation:
We will use the 5 different methods that we learned during class to approximate the root of the given root by simply
defining a new function g such that
1) Bisection: This is the slowest method of the bunch, in this case, we have a general guess of the range where the
root is, bounded by xlower and xupper.
Once we have the range it’s just a matter of doing a simple binary search where for every iteration, we have xresult that’s
the mean between xl and xu, if the mean is positive then we change xupper to be xr else we change xlower to be xr. This
way we slowly get closer and closer to the root until we find a number that’s close enough to the root that we want.
2) Regula-Falsi: This method works very similarly to the previous one, especially in the coding aspect since the binary
search logic it uses is identical to the bisection method but has some important differences.
With this method, we aren’t slowly approaching the root by getting the mean between xl and xu, in this method we are
doing a linear interpolation between xl, xu, f(xl), f(xu) to try a different linear approximation each iteration and this
interpolation gets closer to the root every time. This method's speed heavily depends on the slope of the range we
choose to search.
3) Newton-Raphson: This is the first of the open methods which require initial guesses that don’t need to include the
root that we are looking for between them.
This method is mainly used for functions that have known first derivatives, if we have a good guess of the first derivative
then we can still use it, but it starts to lose reliability.
This is an iterative method that uses a single initial guess and then it starts approaching the root by finding the
intersection on the x-axis of the tangent function at that point and this intersection is our new guess that we can try
again. This method is a very fast way to find the root as long as the convergence conditions hold and we choose the right
initial guess, if we don’t these kinds of methods will diverge, and we won’t get the root that we want.
4) Secant method: This method is essentially the same as the Newton method but with some differences. This is the
method that we need to use when we don’t know the first derivative of the function since this method gives us a good
estimate of the derivative instead of using the actual derivative. Besides this, it’s essentially the same as the Newton-
Raphson method.
5) Modified secant method: this is the same as the original, but we only need one guess, because this method estimates
f’(x) at every iteration but with a small lambda perturbation factor instead of relying on the two initial guesses in the
normal secant method.
Error: for all these methods we are going to use the iterative convergence criterion which means that we will look for a
delta-x < error such that: |xn-1-xn |< 0.0001. In my code this is done by using the check converge function which just
compares xn-1 and xn.
1) Bisection method
2) Regula-Falsi
3) Newton Raphson
4) Secant
5) Modified Secant
In this problem, we will use the previously learned methods to determine the range of convergence for two different
functions. To determine this, we need to find the range of h for which the absolute value of the derivative of the
functions is less than 1.
The two derivatives are d1 and d2 in lines 5 and 6 of the code, after that in lines 9 to 13 we plot the graphs to find the
initial guesses for our ranges.
d1:
d2:
As the last step to determine the range of convergence, we need to find the intersection with 1 and -1 for d1 in lines 16
to 32 and the two intersections of d2 with -1 in lines 35 – 44. And we can safely say that the range of convergence for d1
is -1.5406 < h < 0.04 and for d2 -0.3967 < x < -0.4313 and 0.3967 < x < 0.4313.