Using MatLab: Write a function file that calculates the local extrema (maximum o
ID: 3009014 • Letter: U
Question
Using MatLab:
Write a function file that calculates the local extrema (maximum or minimum) of a quadratic equation of the form f(x) = ax^2 + bx + c. Recall that the condition for an extrema is f?(x) = 0, which is a maximum if f?(x) 0. Name the function [x, y, m] = extrema (a, b, c). The input arguments are the coefficients a, b, and c. The output arguments are x, the coordinate of the extrema; y, the function value at the extrema; and m, which is 1 if y is a maximum and -1 if y is a minimum. (The built-in sign function may be useful.) Use the function to find the maximum or minimum of the following equations: f(x) = 3x^2 - 7x + 14 f(x) = - 5x^2 - 11x + 15Explanation / Answer
function [x,y,m]=extrema(a,b,c)
extrema:maximum or minimum function of a equation
[x,y,m]=extrema(a,b,c):computes extrema value of a function
input:
a=coefficient of x.^2;
b=coefficient of x;
c=constant value;
if y is maximum
[x,y,m]=1
else y is minimum
[x,y,m]=-1
output:
[x,y,m]=extema value of the function;
x=linspace(x,y,m);
y=func(x);
[x,y,m]=exrema(y);