Find the roots of cos(4x) + cos(2x) = 0 for 0 <= x <= 2π ?
Ans. 0.524, 2.62, 3.67, 5.76
There is four roots found. However, if we make a plot for the function :
The resulting graph is :
We can see that there are actually six roots. The two missing ones are those zero points that are just touching the x-axis but not crossing it. For this type of roots, the function zeros failed to detect them.
To find the missing two roots, we noticed that the slope of those roots are 0, therefore we can use the derivative function to detect them. There are several ways to do it. One method is to evaluate the product of f(x) and its derivative df(x)/dx instead of f(x) :
Ans. set y = 0, 0.524, 0.912, 1.57, 2.23, 2.619, 3.14, 3.666, 4.054, 4.71, 5.37, 5.76, 6.283
In using the modified function, we can indeed found all the global/local minimums, global/local maximums and zeros of a function. To distinguish which are the zero points, it is only needed to evaluate their corresponding values :
Ans. 2, -0,0004, -1.12, 0, -1.125, 0.0004, 2, -0.0004, -1.125, 0, -1.125, 0.0004, 2
We can see that the values of the 2th, 4th, 6th, 8th, 10th, 12th are very near to zero, so they are the roots.
In summary, the roots of cos(4x) + cos(2x) = 0 for 0 <= x <= 2π are 0.524, 1.57, 2.62, 3.67, 4.71, 5.76.
One reason we do not implement the above method into the function zeros is because of its long calculation time. Calculation of a function's derivative can cause a significant time delay which in turn determined by our phone's CPU capability. So, if your phone is running fast, you can use the modified function f(x) df(x)/dx to be inserted to function zeros to find roots for f(x).
Next, we will show a common roots finding method called 'Newton-Raphson' (NR) Method. The advantage of this method is that no matter the root is just touching the x-axis or crossing it, it can still work. However, because this method uses recursive sequence, it may not guarantee convergence if we choose the wrong initial point.
To find the root of the function f(x) = 0, NR method uses the following recursive formula :
xi+1 = xi - f(xi)/(df(x)/dx)x = xi
First, we will make a script called 'nr' for this method as follow :
Noticed that the value of y(0) is set to another variable a which we can set it externally.
Now, our script is ready to use. Let us try some examples :
Find one real root of x3 - x - 1 = 0 ?
Ans. set a = 1
This is set to be the initial value of y(0).
The script would be run and the list y is evaluated :
Ans. 1, 1.5, 1.348,......, 1.325
The list converges to 1.325 which is the real root of the equation x3 - x - 1 = 0. We can check this result through the table function :
Ans. 2.22e-16
Alternately, we can also use function zeros and find the same root :
Ans. 1.325
Below is another example :
Find root of x = e-x ?
Ans. set a = 0.5
Ans. 0.5, 0.566, 0.567,......, 0.5671
Since y converges to 0.5671, it is the root. To verify the result, we substitute the value back to the equation :
Ans. -1.1e-16
Also from function zeros :
Ans. 0.567
The Newton-Raphson method can also be used to solve multi-variables non-linear equations :
Suppose we want to find n unknown values x = (x1,....., xn) which
satisfy n non-linear equations fi(x) = 0 where i is ranged from 1 to n the Newton-Raphson recursive formula to solve the problem is : xi+1 = xi - (f1(xi),......, fn(xi))D-1(xi) where D-1 is the inverse matrix of D with items : Dij(x) = ∂fj(x)/∂xiIt should be noticed that the recursive formula is now in vector form and involved a matrix multiplication term. We can also see that when n equal to 1, D becomes a single value, df/dx and D-1 is 1/(df/dx), the formula would becomes the previous NR formula with single variable.
In order to handle matrix operations, we need to introduce two new functions from Mathcalc8, namely 'mmult' and 'inv'. The function mmult is used matrix multiplication and inv is used to calculate the inverse of a matrix.
Below is an example showing how we can solve a set of non-linear equations by multi-variable NR method :
Find solution for the following two equations : f1 = x2 + y2 - 15 = 0
f2 = xy - 5 = 0 for x,y ≥ 0
First, we try the method of 'substitution' to solve this problem. We substitute y = 5/x into equation f1 and uses function zeros :
Ans. 1.381, 3.618
Two roots of 1.382 and 3.618 are found.
It is also noticed that we cannot start the searching from 0 due to the term 5/x on the equation which would gives overflow error immediately.
Now we try the multivariables NR method. First, we need to find the formula for the 2 x 2 matrix D :
D = (∂f1/∂x , ∂f1/∂y) = (2x , 2y) (∂f2/∂x , ∂f2/∂y) ( y , x)
Next,
We set the initial value for x to be 2 and the initial value of y to be 1.
Ans. 2, 4.833,......, 3.618
Ans. 1, -0.333,......, 1.382
The list xx converges to 3.618 and y converges to 1.382. Therefore, one solution of (3.618, 1.382) is found. Moreover, since both x and y are symmetrical on the two equations. We can immediate guess the other solution (1.382, 3.618). These two solutions are in consistence with the values found by function zeros.
One more limitation of function zeros we want to discuss is that the function that we are searching for zero points must be continuous within the searching range that we specified. Below is an example showing this limitation :
Find the roots for x - tan(x) = 0 for 0<= x <= 10 ?
Since tan(x) is not a continuous function within 0 to 10. Applying function zeros to the function x - tan(x) would not work. In general, we need to split our searching range into several continuous ranges to search or in this case, we can modify the equation as follows :
x - tan(x) = x - sin(x)/cos(x) = (x cos(x) - sin(x))/cos(x) = 0
So, the roots of x cos(x) - sin(x), which is a continuous function within 0 to 10, are the same as the original equation.
Ans. 0, 4.4928, 7.7246
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.