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