Find the position of maximum value.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sunny123@ntlworld.com

    Find the position of maximum value.

    hello

    i am trying to find the maximum value of a function and where it occur.

    i.e there is an array

    x |y
    =============
    |
    |
    |
    |
    |
    |

    and i want to find where the maximum occurs and at what value of x.

    i tried fabs but it isnt quite right.

    thanks

  • mlimber

    #2
    Re: Find the position of maximum value.

    Sunny123@ntlwor ld.com wrote:[color=blue]
    > hello
    >
    > i am trying to find the maximum value of a function and where it occur.
    >
    > i.e there is an array
    >
    > x |y
    > =============
    > |
    > |
    > |
    > |
    > |
    > |
    >
    > and i want to find where the maximum occurs and at what value of x.
    >
    > i tried fabs but it isnt quite right.[/color]

    Show us the code, and we might be able to help. Be aware, though, that
    this forum is for discussing the C++ language in particular, not
    programming or applications in general. See this FAQ for what is
    on-topic here:



    Cheers! --M

    Comment

    • Victor Bazarov

      #3
      Re: Find the position of maximum value.

      Sunny123@ntlwor ld.com wrote:[color=blue]
      > i am trying to find the maximum value of a function and where it
      > occur.
      >
      > i.e there is an array
      >
      > x |y
      > =============
      > |
      > |
      > |
      > |
      > |
      > |
      >
      > and i want to find where the maximum occurs and at what value of x.
      >
      > i tried fabs but it isnt quite right.[/color]

      I believe some of it is covered in the FAQ (you can find the FAQ
      here: http://www.parashift.com/c++-faq-lite/)

      Start in section 5.

      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask


      Comment

      • Jim Langston

        #4
        Re: Find the position of maximum value.

        <Sunny123@ntlwo rld.com> wrote in message
        news:1147370036 .197283.27950@j 33g2000cwa.goog legroups.com...[color=blue]
        > hello
        >
        > i am trying to find the maximum value of a function and where it occur.
        >
        > i.e there is an array
        >
        > x |y
        > =============
        > |
        > |
        > |
        > |
        > |
        > |
        >
        > and i want to find where the maximum occurs and at what value of x.
        >
        > i tried fabs but it isnt quite right.[/color]

        Show us what you tried with fabs.


        Comment

        • osmium

          #5
          Re: Find the position of maximum value.

          <Sunny123@ntlwo rld.com> wrote:
          [color=blue]
          > i am trying to find the maximum value of a function and where it occur.
          >
          > i.e there is an array
          >
          > x |y
          > =============
          > |
          > |
          > |
          > |
          > |
          > |
          >
          > and i want to find where the maximum occurs and at what value of x.
          >
          > i tried fabs but it isnt quite right.[/color]

          I doubt if fabs has any bearing on your problem. Try something like this.

          double lsf = a[0]; // lsf - largest so far, a - array
          int lsf_ix = 0;

          Now go through the array, starting at index = 1, modifying lsf and lsf_ix as
          appropriate. This does not find the maximum of f(x) in a mathematical sense,
          it only finds the best estimate contained in the array you have created.
          But I suspect you knew that.


          Comment

          • Richard Herring

            #6
            Re: Find the position of maximum value.

            In message <4cjg51F15v99aU 1@individual.ne t>, osmium
            <r124c4u102@com cast.net> writes[color=blue]
            ><Sunny123@ntlw orld.com> wrote:
            >[color=green]
            >> i am trying to find the maximum value of a function and where it occur.
            >>
            >> i.e there is an array
            >>
            >> x |y
            >> =============
            >> |
            >> |
            >> |
            >> |
            >> |
            >> |
            >>
            >> and i want to find where the maximum occurs and at what value of x.
            >>
            >> i tried fabs but it isnt quite right.[/color]
            >
            >I doubt if fabs has any bearing on your problem. Try something like this.
            >
            >double lsf = a[0]; // lsf - largest so far, a - array
            >int lsf_ix = 0;
            >
            >Now go through the array, starting at index = 1, modifying lsf and lsf_ix as
            >appropriate. This does not find the maximum of f(x) in a mathematical sense,
            >it only finds the best estimate contained in the array you have created.
            >But I suspect you knew that.
            >[/color]

            If you're looking for a C++ solution, std::max_elemen t() will give the
            position (an iterator to) the maximum element of a sequence, for a
            possibly user-defined meaning of "maximum".

            --
            Richard Herring

            Comment

            Working...