:confused: HI, I need to create a program which tests whether within a range given by the user, there exists an extreme of quadratic function (y=ax2+bx+c). The parameters (a,b,c) of this function are given by the user. I just started it but I have a problem in completing it. This is how far I can go.
#include <stdio.h>
int x;
int y;
int a,b,c;

:confused: HI, I need to create a program which tests whether within a range given by the user, there exists an extreme of quadratic function (y=ax2+bx+c). The parameters (a,b,c) of this function are given by the user. I just started it but I have a problem in completing it. This is how far I can go.
#include <stdio.h>
int x;
int y;
int a,b,c;

Can you explain what you mean more clearly?

``````#include <stdio.h>
int x;
int y;
int a,b,c;

int main()
{

return 0;
}``````

Do u need a complete program for this I justcreated one for calculating the roots of QUADRATIC EQUATIONS.
Replyto this if u need one or anyone else will copyit and use it.

No, that's not what's being asked for. honeybleak, do you know how to do the calculation on paper?

That link has nothing to do with finding the global extremum, which is located at -b/2a. (If a = 0 then there is no global extremum.)

What does your avatar mean or represent Mr Rashakil? Remember the ancient dragon is no maths wizz kid :-)

I don't think it's a question of math, people just misinterpreted the problem (or had read the first misinterpretation of the problem). Why would I tell anybody what my avatar is?

you have to check the bounds. i.e. if someone inputs the range ( -1 , 2 ). you should check the following.

let f(x) = ax^2 + bx + c .
check f(-1), f(2) and f(-b/2a).

since this is a quadratic it can be assumed that a != 0.

if you are looking for mins and max those are the only possible places they can occur ( local extrema f(-1), f(2) ) and a global extrema f(-b/2a).

That link has nothing to do with finding the global extremum, which is located at -b/2a. (If a = 0 then there is no global extremum.)

sorry, I thought you wanted to know how to calculate quadritic equation. Beyond that, I don't have a clue how to solve your problem.

This is the real one.

``````#include <stdlib.h>
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<dos.h>
void main()
{
restart:
;
clrscr();
float a,b,c,x,y,d,d2,b2,a2,n1,n2,o;
a=b=c=d=x=y=a2=b2=d2=n1=n2=o=0;
char ch;
cout<<"\nEquation must be in the form of ax"<<(char)253<<"+bx+c=0"<<endl<<endl;
cout<<"\nPlease enter the value of co-efficient a: ";
cin>>a;
cout<<"\nPlease enter the value of co-efficient b: ";
cin>>b;
cout<<"\nPlease enter the value of co-efficient c: ";
cin>>c;
b2=pow(b,2);
o=4*a*c;
a2=2*a;
d=b2-o;
cout<<"\nThe Discriminent is "<<d;
if(o>b2)
{
cout<<"\n\nSorry....Discriminent is negative.Solution not possible";
goto breakend;
}

d2=sqrt(d);
n1=-b-d2;
n2=-b+d2;
x=n1/a2;
y=n2/a2;
cout<<"\n\nWait.....Input is being processed.....";
delay(500);
cout<<"\n\nThe ROOTS are \n x =  "<<x<<" , "<<y;
breakend:
;
cout<<"\n\nDo you Want to continue?(y/n)...";
cin>>ch;
if(ch=='y'||ch=='Y')
goto restart;
else
cout<<"\n\nGood Bye...";
getch();
}
``````

if u use this u will realy like it.

>Why would I tell anybody what my avatar is?

Why not? Do the dots represent the number of times you've been rejected?
:cheesy:

Hmm...

That seems like a good Quadratic Solver, but that wasn't the question. The question was minima and maxima. This should work
i haven't tested it thoroughly.

``````#include <iostream>
#include <stdlib.h>
using namespace std;

int main( int argc, char **argv ) {

double a, b, c, slope, lower, upper, f_lower, f_upper, f_slope;
double min, max;

if( argc != 6 ) {
cerr << argv << " <a> <b> <c> <lower> <upper>\n";
exit(-1);
}

a = atof( argv );
if( a == 0 ) {
cerr << "Since a is zero this is not a quadratic. Exiting.\n";
exit(-1);
}
b = atof( argv );
c = atof( argv );

lower = atof( argv );
upper = atof( argv );

slope = (-b / (2.0*a) );

f_lower = ( lower*lower*a + b*lower + c );
f_upper = ( upper*upper*a + b*upper + c );
f_slope = ( slope*slope*a + b*slope + c );

if( slope >= lower && slope <= upper ) {

if( f_slope <= f_lower && f_slope <= f_upper ) {
cout << "Min: x = " << slope << ", f(" << slope << ") = " << f_slope << " \n";
if( f_lower <= f_upper )
cout << "Max: x = " << upper << ", f(" << upper << ") = " << f_upper << " \n";
else
cout << "Max: x = " << lower << ", f(" << lower << ") = " << f_lower << " \n";
}
else {
if( f_lower <= f_upper )
cout << "Min: x = " << lower << ", f(" << lower << ") = " << f_lower << " \n";
else
cout << "Min: x = " << upper << ", f(" << upper << ") = " << f_upper << " \n";
cout << "Max: x = " << slope << ", f(" << slope << ") = " << f_slope << " \n";
}

}
else {
cout << "The extrema is out of range so the minimum and maximum \n";
cout << "  values occur on the boundaries\n\n";

if( f_lower <= f_upper ) {
cout << "Min: x = " << lower << ", f(" << lower << ") = " << f_lower << " \n";
cout << "Max: x = " << upper << ", f(" << upper << ") = " << f_upper << " \n";
}
else {
cout << "Min: x = " << upper << ", f(" << upper << ") = " << f_upper << " \n";
cout << "Max: x = " << lower << ", f(" << lower << ") = " << f_lower << " \n";
}

}

}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.