Write a user defined function that calculates the maximum or minimum of a quadra
ID: 3633371 • Letter: W
Question
Write a user defined function that calculates the maximum or minimum of a quadratic equation of the form:f(x)= ax^2+bx+c
Name the function [x,y,w] = maxormin (a,b,c). The input arguments are the coefficients a,b, and c. The output arguments are x, the coordinate of the maximum (or minimum); y, the maximum (or minimum) value; and w, which is equal to 1 if y is a maximum equal to 2 if y is a minimum.
Use the function to determine the maximum or minimum of the following function:
(a) f(x)= 3x^2-7x+14
Explanation / Answer
So to calculate the vertex of a quadratic, you use (-b/2a) To find y, evaluate f(x) at (-b/2a) To determine whether z is 1 or z is 2: ---a quadratic has a max when 'a' is less than zero. This means the graph a hill ---a quadratic has a min when 'a' is greater than zero. This means the graph is a valley I've included the code and your test case of f(x) = 3x^2-7x+14 below. Good luck! Here is the code: function [ x,y,z ] = maxormin( a,b,c ) %maxormin returns: %x: the coordinate of the max or min vertex %y: the max or min value %z: 1 if y is max, 2 if y is min x = -b/2*a; %the coordinate of the min or max vertex y = a*x^2+b*x+c; %the value of y or f(x) at the minimum or maximum if a>0 z = 2; %if a>0 then the function has a minimum end if a [x,y,z]=maxormin(3,-7,14) x = 10.5000 y = 271.2500 z = 2Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.