473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2675
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Raed Sawalha | last post by:
I have following XML: How can I find the depth of XML? in other word max level of the XML <Root> ----- level 0 <Name>----- level 1 <FirstName>name</FirstName> ---- level 2...
11
by: ex laguna | last post by:
How do I find the lowest bit position of a mask using only macros? I want to do everything in compile time. That mean, there cannot be control statements such as if, while, for, etc. in the...
6
by: Colin McGuire | last post by:
Hello experts, this is a repost but I have been (much) more clear. I want to know the position of the horizontal scrollbar in a textbox as a percentage - if the horizontal scrollbar is hard...
0
by: JR | last post by:
Hi, i found a user control on the net see code below it is part of VSEssential but I like the coolProgressBar. Zo I want to use it into my program and I always get the error that it can't find...
2
by: mmdst23 | last post by:
I'm working on a video player app, and I want to implement a trackbar that behaves like the one in Media Player, that is the cursor position moves to where the user clicked instead of moving in...
2
choke
by: choke | last post by:
I need to write a function in devc++ that creates an array of n integers, each element is equal to n*n+i*i-n*i where i is from 0 to n-1 as the array index. Within the same function I need to find...
4
by: raylopez99 | last post by:
I would like to know if there's a quick "Linq" way to find the index of an array having a particular value. I can do this the long way by sequential iteration, but would like to know if there's a...
12
Frinavale
by: Frinavale | last post by:
I think I'm trying to do something impossible. I have a <div> element with a overflow style set to "scroll". In other words my <div> element allows the user to scroll the content within it. ...
1
by: spynx | last post by:
import javax.swing.JOptionPane; import java.io.*; import java.util.Arrays; public class election5 { public static void main( String args ) {
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.