### Max/Min of a quadratic equation

Hey guys, I was just wondering is there any way to use c++ to find the max/min of a quadratic equation?
Yea, but I wasn't talking about the roots. I was talking about the min and max. In other words, the point on the equation with the max value of y, and the min value of y.
In math you differentiate the equation and set the answer to zero, to find the min or max. I wanted to know if there is something similar that can be done in c++

mmmm i wright this for my h.w look out the output ^_^

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677`` ``````#include using namespace std; int main() { double value,min,max,avg,sum; int count; int Degree; count=0; min=0.0; max=0.0; sum=0.0; cout<<"put your value ^_^ ,if you want stope put -1 like a value please "<>value; while(value!=-1)//if you want stope put -1 like a value please { sum +=value; count++; if(value>max) max=value; else if(value>value; } cout<<" the max value is "<>Degree; if(Degree>=avg) cout<<"pass"<
I started out posting regarding the roots (which is a different topic).
What you need is to find where the slope of the curve is zero. I suppose you could input the coefficients a,b and c, then follow some simple rules to get the derivative.

f(x) = a*x^2 + b*x + c

differentiate
f'(x) = 2*a*x + b

Max or min when 2*a*x + b = 0
Hence
x = -b/ (2 * a)
Then find the value of the original function f(x) for that value of x.

 ``1234567891011121314151617`` ``````#include class quadratic { double a, b, c; public: quadratic(double A, double B, double C) : a(A) , b(B), c(C) {}; double fx(double x) { return a*x*x + b*x + c; } double maxminX() { return -b / (2.0 * a); } double maxmin() { return fx(maxminX()); } }; int main() { quadratic equation(-2, 36, -177); std::cout << "max or min at x = " << equation.maxminX() << std::endl; std::cout << "max or min is " << equation.maxmin() << std::endl; }``````

Output:
 ```max or min at x = 9 max or min is -15```

Last edited on
C++ doesn't do calculus for you, but as Chervil says, you can write a program in C++ to do calculus.

You can also pick up a library, this seems promissing:
http://www.gnu.org/software/gsl/
Last edited on
Thanks guys, any other thoughts on this topic?
That's an open-ended question. Can you be more specific please?
I suppose you could input the coefficients.. http://www.hqew.net
Topic archived. No new replies allowed.