Skip to main content
1-Visitor
August 9, 2013
Question

finding the maximum

  • August 9, 2013
  • 2 replies
  • 1658 views

Could some one point out where im going wrong in finding the maximum of my function. I thought it should be trivial.

I want to create a generic way to pass any function. Please see attached.

Thanks

Jason

2 replies

Jbryant611-VisitorAuthor
1-Visitor
August 9, 2013

Its OK, I've done it. I changed the order of the two line sin the for loop and it worked 😉

Jason

25-Diamond I
August 9, 2013

Or maybe better using just one if-statement

maxfunc1.png

or even a more analytical approach (with all limitations of root, of course) which will yield more precise results more quickly

maxfunc2.png

24-Ruby IV
August 9, 2013

Or

thru.png

25-Diamond I
August 9, 2013

Here is a version with some error handling which should work even if the extremum is not between xlo and xhi.