954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I need help urgently on Arrays and functions

: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
int x;
int y;
int a,b,c;

honeybleak
Newbie Poster
1 post since May 2006
Reputation Points: 10
Solved Threads: 0
 
: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 int x; int y; int a,b,c;

Can you explain what you mean more clearly?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
#include <stdio.h>
int x;
int y;
int a,b,c; 

int main()
{
   // put your code here


  return 0;
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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.

Cool Nanu
Newbie Poster
10 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 

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

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

see this article

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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.)

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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?

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

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).

soxers12
Newbie Poster
4 posts since May 2006
Reputation Points: 10
Solved Threads: 1
 
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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This is the real one.
#include
#include
#include
#include
#include
void main()
{
restart:
;
clrscr();
cout<<"\n\n\t\t\tQuadratic Equation Calculator\n\t\t\t\tby ANIRUDH SANYAL"<>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 "<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 = "<>ch;
if(ch=='y'||ch=='Y')
goto restart;
else
cout<<"\n\nGood Bye...";
getch();
}

if u use this u will realy like it.

Cool Nanu
Newbie Poster
10 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 

>Why would I tell anybody what my avatar is?

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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[0] << " <a> <b> <c> <lower> <upper>\n";
      exit(-1);
    }

    a = atof( argv[1] );
    if( a == 0 ) {
      cerr << "Since a is zero this is not a quadratic. Exiting.\n";
      exit(-1);    
    }
    b = atof( argv[2] );  
    c = atof( argv[3] );
    
    lower = atof( argv[4] );
    upper = atof( argv[5] );
    
    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";
      }
   
    }

  
}
soxers12
Newbie Poster
4 posts since May 2006
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You