Chemist using c++ to solve an equation..

January 9, 2011 at 10:55:13
Specs: Macintosh
Hey guys,

Just wondering if anyone could help me here..

I'm looking to perform a calculation over a range (say v= 0 - 100) and for C++ to display what the highest value of the equation is and for what value of v this occurs at.

e.g.
for (v=0; v<=100; v++) {
p = exp((v+0.5)*h*nu)/q; }

Thanks :)


See More: Chemist using c++ to solve an equation..

Report •


#1
January 9, 2011 at 13:07:22
inside your loop you can add an if statement.

if(p > max_value) { max_value = p; index_at = v; }


Report •

#2
January 9, 2011 at 13:49:45
Thanks - so is that an if () break clause?

Sorry, I'm a bit of a newbie at this :)


Report •

#3
January 9, 2011 at 15:37:51
Unless you're sure the max would occur prior to the last iteration of v, you might as well let the loop terminate on its own. Try graphing the equation to see what it does.

Report •
Related Solutions


Ask Question