473,699 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2703
Su******@ntlwor ld.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******@ntlwor ld.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******@ntlwo rld.com> wrote in message
news:11******** *************@j 33g2000cwa.goog legroups.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******@ntlwo rld.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.ne t>, osmium
<r1********@com cast.net> writes
<Su******@ntlw orld.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_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
May 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8442
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 <LasName>lname</LastName> <MiddleName>mName<MiddleName> </Name>
11
10500
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 macro. Note that the macro takes only one (1) argument, the mask. Examples: // Mask Lowest bit position
6
10936
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 left, I want to display 0% on the form. - if the horizontal scrollbar is smack in the middle, I want to display 50% on the form. - if the horizontal scrollbar is 2/3rd along the X-axis,
0
1813
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 the control or the control isn't into the toolbar Who has an idee Jan
2
10183
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 that direction by a fixed value. Has anyone implemented something like this before? I haven't found anything on codeproject, or searching the .NET newsgroups. This seems like it would be a common control type, am I missing the easy solution? I...
2
2638
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 the maximum value, minimum value and average of all elements. I'm stuck on the first one :/ I've practiced calling another function to find the maximum, and that seemed to work fine. I get a number in the millions when trying to do this all in one...
4
9983
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 shortcut. Specifically, you have an Array, say an array of Ints. You have a maximum value, i.e. int someValue = Array.Max(); and you would like to know which ith cell of the Array holds this value. How to do this without iterating the entire...
12
7861
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. There are a number of elements within this <div> that cause the <div> to participate in an Ajax call to the server. In order to maintain the scroll position of the <div> during the Ajax request I store the scroll value in a hidden field so that when...
1
1922
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
8704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9187
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.