470,811 Members | 1,154 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,811 developers. It's quick & easy.

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

May 11 '06 #1
5 2466
Su******@ntlworld.com wrote:
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.


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:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

May 11 '06 #2
Su******@ntlworld.com wrote:
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.


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
May 11 '06 #3
<Su******@ntlworld.com> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
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.


Show us what you tried with fabs.
May 11 '06 #4
<Su******@ntlworld.com> wrote:
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.


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.
May 12 '06 #5
In message <4c*************@individual.net>, osmium
<r1********@comcast.net> writes
<Su******@ntlworld.com> wrote:
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.


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.


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

--
Richard Herring
May 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Raed Sawalha | last post: by
6 posts views Thread by Colin McGuire | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.