Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help on writing on scrip to find the real finite and extremal point and a

ID: 2962077 • Letter: I

Question

I need help on writing on scrip to find the real finite and extremal point and also code for plotting the graph.




In this homework, you will write a Matlab script called ratminmax. m which computes the finite "extremal" (min/max) points of a rational function (defined as a function represented by a ratio of polynomials). From calculus, we know that the (finite) extremal points of a function f(x) can be found by solving the equation df(x)/dx = 0 For a rational function f(x) = p(x)/q(x), where p(x) and q(x) are polynomials, recall the quotient rule for derivatives d/dx (p(x)/q(x)) = p'(x)q(x) - p(x)q'(x)/q(x)2 where p'(x) = dp(x)/dx and q'(x) = dq(x)/dx. Note that the denominator is nonnegative, and finite for any finite x. Thus, the condition for a finite extremal point becomes more simply: p'(x)q(x) - p(x)q'(x) = 0 (Note that a possible problem can arise in this calculation if q(x) has real roots, since then there exist real values of x for which q(x) = 0 so that f(x) and its derivative actually become infinite. Your code can assume that real zeroes of q(x) will not exist for the problems you are given; thus you don't need to worry about this case). Your script should assume that coefficient arrays p and q have been defined in the workspace corresponding to the polynomials in the numerator and denominator respectively of f(x). It should then compute the real, finite, extremal points using the equation above. Then, the script should plot the entire function f(x) = p(x)/q(x); the range of x values used in the plot should extend 2 units past the location of the furthest extremal points in each direction. Use a grid spacing of 0.01 for the x values in this range. Label the axes x and f(x), and title the graph "Extremal points of f(x)=p(x)/q(x)". Finally, your script should label each extremal point on the graph of f(x) with a red circle, as well as printing out the x coordinates of each extremal point. There should be no other output from your script. As an example, if p contains the coefficients corresponding to the polynomial p(x) = x5 - x4 - 13x3 - 9x2 + 42x + 40, and q has coefficients corresponding to q(x) = x2 + 2x + 5, then there are finite extremal points at x = 3.11 and x = 0.44, and the plot output from the script should look like that shown in the attached figure. NOTES: Do not use symbolic calculation techniques. Your code must work solely with the numerical coefficient arrays of the polynomials. Note that the derivative of a polynomial is also a polynomial. The Matlab command polyder will give you the coefficient array for the derivative of a polynomial. For example, dp=polyder(p) will result in dp holding the array of coefficients for the derivative of the polynomial represented by array p.

Explanation / Answer

clear all

close all

clc

p=[1 -1 -13 -9 41 40];

q=[1 2 5];

dp=polyder(p);

dq=polyder(q);

z=conv(q,dp)-conv(p,dq);

x=roots(z);

x=x(imag(x)==0);

disp(x)

r=-2:0.01:6;

f=polyval(p,r)./polyval(q,r);

f1=polyval(p,x(1))/polyval(q,x(1));

f2=polyval(p,x(2))/polyval(q,x(2));

plot(r,f,x(1),f1,'o',x(2),f2,'o');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote