Find the position of maximum value.

S

Sunny123

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
 
M

mlimber

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-lite/how-to-post.html#faq-5.9

Cheers! --M
 
V

Victor Bazarov

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
 
J

Jim Langston

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

osmium

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

Richard Herring

osmium said:
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".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top