Finding solutions to equations graphicallyWe illustrate the graphical solution of equations in the following example.Example 1:Find all solutions of the equationx3 = 20 cos x“Graphical Solutions to Equations”−3 −2 −1 0 1 2 3−30−20−100102030plot of x3 and 20*cos(x)about −2.5about −2.0about 1.4Figure 1: Plot of x3 and 20 cos(x). The solutions to the equation x3 = 20 cos(x) are the xvalues of the intersection points.Step 1. Plan you actions We will graph both f(x) = x3 and g(x) = 20 cos x and look for intersectionpoints. Alternatively, you could plot f(x) = x3−20 cos(x) and look for its zeroes.To find an appropriate viewing window, we notice that when x = 3 we have x3 = 27 whichis already more than 20, the largest 20 cos(x) can be. By symmetry, we will choose theinterval [−3, 3] for our initial plot (Figure 1). If this isn’t large enough, or is too small wewill make an adjustment and replot.Step 2. Make the plot(s) The graph is created with these commands>> x = linspace(-3,3);>> y1 = x.^3;>> y2 = 20*cos(x);>> plot(x,y1, x,y2)You could also use hold here and make the plots incrementally.Step 3. Investigate the graph Looking at the graph, we can see that the solutions are about−2.5, −2.0, and 1.4, but we can do better by zooming in around these intersection points.Step 4. Zoom in Let’s find the value of the root near 1.4. First we check if 1.4 is very close bylooking at the difference between the two functions:http://www.math.csi.cuny.edu/matlab project 4 page 2“Graphical Solutions to Equations”>> x = 1.4x = 1.4000>> x^3 – 20*cos(x)ans = -0.65534We are not very close. We turn the zoom feature on using the magnifying glass icon, or thezoom function and then click near the intersection point. The plot is redrawn with half the xand y axes. We see the answer is closer to 1.42. Clicking again, we see that a value of 1.425seems about right. We check to see how close we are>> x = 1.425x = 1.4250>> x^3 – 20*cos(x)ans = -0.0120It is not exact (1.4255 is closer), but we have to be careful when we zoom in too close,as our graph may not accurately portray the actual function. Recall we have plotted 100points evenly spaced between -3 and 3 so that roughly there are 16 points between 1 and2. After zooming in this closely, the plot is made up of just a few line segments, whereasthe functions’ graph is actually a curve. To get more accuracy, it is best to replot with morepoints in the neighborhood of the answer you are looking at.Although zooming is valuable to quickly find pretty good answers, there are other methodsfrom numerical analysis which are more accurate. In a later project we explore one calledNewton’s method.Exercise 1:Use a graph of (x − 2)2 = 4 sin(x) to find solutions to the equation valid to 2 decimal points:(1) Answer:Exercise 2:Use the zooming technique to find solutions of50 + sin x = 2x.which are valid to at least two decimal places.Hint: Try to estimate the value of 50 + sin x. This will give you an idea in which x interval are thepossible solutions!(2) Answer:http://www.math.csi.cuny.edu/matlab project 4 page 3“Graphical Solutions to Equations”Exercise 3:Folklore is that exponential functions grow faster than polynomial functions. Although true, youneed to be careful about how you interpret this statement, as this exercise shows.Consider the functions z1 = ex and z2 = x4. Plot them together on the interval [0,4].a. From their graphs, how can you determine which graph is the exponential and which is thepolynomial?(3) Circle one:1. polynomial functions grow faster than exponential functions2. Exponential functions grow faster than polynomial functions3. For different values of x, I can evaluate z1, z2 and determine which is larger.b. Find the value of x (to two decimal places) for the point of intersection by zooming on thezero of f(x) = ex − x4. (or by zooming on the intersection point of the functions z1 = ex,z2 = x4.)(4) Answer:On this graph, x4 is larger than ex from the intersection point to x = 4. Experiment todetermine how large a value of x is needed for the exponential to catch up to x4. Then findthe second intersection point. (correct to three decimal places.) This one is larger than 4. Infact, you now have found two intersection points (x1, y1), (x2, y2). (where x1 < x2) Up to x1the function ex is bigger, from x1 to x2 the function x4 is the bigger. What happens after x2?c. What is the x-coordinate of the second intersection point?(5) Answer:d. What happens to the behavior of z1 and z2 after the second intersection point?(6) Circle one:1. ex grows faster2. x4 grows faster3. they grow at the same rate4. ex grows faster, but for increasingly large values of x, x4 catches up to ex again.Vertical asymptotes can be a real impediment to finding roots, as this example illustrates.Example 2:Find any zeroes and the minimum value of the rational functionf(x) =x + 2×2 .We first graph the function over initial interval [−10, 10] producing Figure 2.http://www.math.csi.cuny.edu/matlab project 4 page 4“Graphical Solutions to Equations”−10 −8 −6 −4 −2 0 2 4 6 8 10−50050100150200250Figure 2: The function f(x) = (x + 2)/x2 illustrating a vertical asymptote.The figure illustrates that the vertical asymptote at x = 0 gets in the way of finding the twoanswers we want—the zeroes and the minimum value. Let’s try again using a little thought beforewe chug ahead with the computer.Recall that rational functions are 0 only when the numerator is, that is when x + 2 = 0, orx = −2. The function goes from negative to positive there, so the minimum must be located to theleft of −2. As this function has a horizontal asymptote of y = 0 there must be a minimum to theleft of −2, and no minimum to the right of 0 where the function is positive. You’ll do the rest inthe following exercise.Exercise 4:a. Find the x-coordinate for where f(x) = (x + 2)/x2 achieves its minimum value.(7) Answer:b. What interval on the x-axis did you use to make you plot window?(8) Answer:http://www.math.csi.cuny.edu/matlab project 4 page 5“Graphical Solutions to Equations”3 Finding roots of polynomialsPolynomial functions are extensions of linear and quadratic functions (a 6= 0):f(x) = ax + b, (linear) f(x) = ax2 + bx + c (quadratic).For these two types of functions we can solve f(x) = 0 easily. For the linear case the singlesolution is −b/a. For the quadratic case the quadratic formula produces two answers. Theseanswers are the roots of the polynomial.The quadratic formula produces two roots, although many possible cases exist: two distinctreal roots, double roots, or two complex-valued roots that come in conjugate pairs. There are alwaysno more than 2 real roots.A general polynomial of degree n may be written asf(x) = anxn + an−1xn−1 + · · · a2x2 + a1x1 + a0.For an nth degree polynomial there are n, possibly complex, roots counting multiplicities. Butthey need not all be real roots. However, there is not always a formula for solving for these roots.However, MATLAB has a built-in function, called roots, that numerically solves for the roots,which is faster and more accurate than the zooming technique. To use roots, you must code thepolynomial f(x) like a vector. We take each coefficient (there are n + 1) and enter them in orderas follows:The polynomial f(x) is represented with>> p = [an an−1 · · · a2 a1 a0]Then the polynomial equation f(x) = 0 is solved with the command>> roots(p)The only subtlety is that we don’t usually write the terms whose coefficients are 0, but we mustdo so when entering in the polynomial into MATLAB. So, for instance[3 2 1] represents f(x) = 3×2 + 2x + 1,[3 2 1 0] represents f(x) = 3×3 + 2×2 + x,[3 2 0 1] represents f(x) = 3×3 + 2×2 + 1, and[3 0 0 2 1] represents f(x) = 3×4 + 2x + 1.Example 3:Use the roots function to find the roots of f(x) = 2×3 + 6×2 − 4x − 5.>> p = [2 6 -4 -5]p =2 6 -4 -5>> roots(p)http://www.math.csi.cuny.edu/matlab project 4 page 6“Graphical Solutions to Equations”ans =-3.37321.0675-0.6943We get 3 real roots. We could verify this by plotting the polynomial over the interval [−4, 2]and observing the graph crosses the x axis three times. Instead, we illustrate that these are roots,by evaluating the polynomial at these values:>> x = roots(p) % store the values>> 2*x.^3 + 6*x.^2 -4*x -5 % evaluate the polynomial for rootsans =1.0e-13 *-0.31970.04440These values are very close to 0, as they are multiplied by 1.0e-13. This is MATLAB’s scientificnotation for 10−13.Exercise 5:a. Let f(x) = x3 − 7×2 + 2x + 9. Solve the cubic equation f(x) = 0. Find all of its rootscorrectly up to 4 significant digits.(9) Circle one:1. 6.6 , 1.1 -0.72. 6.4766, 1.4692, -0.94583. 6.7053 , 1.3259 , -0.82594. 0.0010, 1.0100, 7.59025. 6.5806 , 1.1062, -0.6868b. Now find all solutions to x3 + 2x + 4 = 0 (Note that the coefficient of x2 is now 0).(10) Circle one:1. 0.6641, -0.6640, -1.32832. 1.8230, -1.8230, -1.32833. 0.5898 ± 1.7445i −1.17954. 1.8230 ± 0.6641i , -1.3283This last exercise illustrates that both means of finding zeroes of functions can be useful.http://www.math.csi.cuny.edu/matlab project 4 page 7“Graphical Solutions to Equations”Example 4:The flight of an arrow through space can be modeled with or without air resistance. How do themodels differ?lllllllllllllllllllllllllllllllllllAn arrow’s flightxyqFigure 3: Flight of an arrow without air resistance.When an arrow encounters no air resistance the laws of projectile motion from high-schoolphysics apply. Using x for the horizontal distance traveled, f(x) for the height of the arrow whenit is x units away, and for the initial angle, we have this model for the trajectory of an arrowwithout air resistance:f(x) = tan x − 16 x200 cos 2When there is a drag on the arrow proportional to its velocity (k is the proportion factor), theheight of the arrow is given by:g(x) = tan()x +32k200 cos x −32klog200 cos 200 cos − x.For both models, the range of flight is the time that y 0. (When y 0, the definition of bothg(x) and f(x) should be set to 0.) The range can be written as [0, b].First, we investigate an arrow’s flight without wind resistance.http://www.math.csi.cuny.edu/matlab project 4 page 8“Graphical Solutions to Equations”Exercise 6:a. Let = /4. Look carefully at f(x), it is a quadratic polynomial in x. Rewrite f(x) so thatthe coefficients appear as (careful with the scientific notation)f(x) = ax2 + bx + c.Now represent this polynomial in MATLAB, as in [a b c]. What are the values:(11) Answer:b. Use your previous answer and the roots function to find the range ([0, b]) of an arrow whenshot at an angle of /4. Specify the range in terms of its endpoint b.(12) Answer:Next, we consider the model with wind resistance. To keep matters simple, we assume k = 1/2.Then our formula for the trajectory when = /4 becomes, in MATLAB,>> theta = pi/4;>> k = 1/2>> a = 200*cos(theta);>> b = 32/k;>> g = (tan(theta)+ b/a)*x – b*log(a ./(a-x));provided you have defined values for x.http://www.math.csi.cuny.edu/matlab project 4 page 9“Graphical Solutions to Equations”Exercise 7:a. Plot various graphs of the g(x) until you find the range of g, [0, b]. Enter the value of b withat least 1 digit to the right of the decimal point. (Remember, arrows don’t bounce up – thismathematical model is only valid until the arrow first hits the ground.)(13) Answer:b. Now make a plot containing the trajectories of both models. Label the individual plots.(14) Attach your graph to the worksheet.c. From your graph estimate the maximum height of the arrow if there is no wind resistance.(15) Answer:d. From your graph estimate the maximum height of the arrow if there is wind resistance.(16) Answer:4 Extra credit problem(To be handed in on a separate sheet of paper.)It can be shown that the maximum range for the arrow if there is no wind resistance happenswhen = /4. However, this is not the case for the model with wind resistance. By exploringaround with different values of , find a value of that maximizes the trajectory