POV-Ray : Newsgroups : povray.general : How to find the maximum value of a function? Server Time
27 Nov 2024 10:47:15 EST (-0500)
  How to find the maximum value of a function? (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: SharkD
Subject: How to find the maximum value of a function?
Date: 14 Nov 2008 23:20:00
Message: <web.491e4dc3b6b31080cb91b1100@news.povray.org>
I have defined a function (function "fn_E", below) and would like to determine
a. the maximum possible value of the function, and b. the coordinates where the
maximum occurs. How can I accomplish this?

Thanks!

-Mike

#declare Blob_threshold = 0.2;
#declare Blob_start = 1;
#declare Blob_radius = 1;
#declare fn_A = function { pow(x+1,2) + pow(y,2) + pow(z,2) - pow(Blob_radius,2)
};
#declare fn_B = function { pow(x-1,2) + pow(y,2) + pow(z,2) - pow(Blob_radius,2)
};
#declare fn_C = function { Blob_start + Blob_threshold }
#declare fn_D = function { pow(Blob_threshold, fn_A(x,y,z)) +
pow(Blob_threshold, fn_B(x,y,z)) - fn_C(x,y,z) };
#declare fn_E = function { max(0,fn_D(x,y,z)) };


Post a reply to this message

From: triple r
Subject: Re: How to find the maximum value of a function?
Date: 15 Nov 2008 03:30:01
Message: <web.491e87e7c0004fc9ef2b9ba40@news.povray.org>
"SharkD" <nomail@nomail> wrote:
> I have defined a function (function "fn_E", below) and would like to determine
> a. the maximum possible value of the function, and b. the coordinates where the
> maximum occurs. How can I accomplish this?
>
> Thanks!
>
> -Mike
>
> #declare Blob_threshold = 0.2;
> #declare Blob_start = 1;
> #declare Blob_radius = 1;
> #declare fn_A = function { pow(x+1,2) + pow(y,2) + pow(z,2) - pow(Blob_radius,2)
> };
> #declare fn_B = function { pow(x-1,2) + pow(y,2) + pow(z,2) - pow(Blob_radius,2)
> };
> #declare fn_C = function { Blob_start + Blob_threshold }
> #declare fn_D = function { pow(Blob_threshold, fn_A(x,y,z)) +
> pow(Blob_threshold, fn_B(x,y,z)) - fn_C(x,y,z) };
> #declare fn_E = function { max(0,fn_D(x,y,z)) };

In general?  I would evaluate it on a sparse grid, then refine that guess with
something like Powell's method or conjugate gradient.

Here?  The maximum is at (1,0,0), and happens to be equal to 34.5012.

 - Ricky


Post a reply to this message

From: SharkD
Subject: Re: How to find the maximum value of a function?
Date: 15 Nov 2008 05:40:01
Message: <web.491ea6a6c0004fc9d43c2bae0@news.povray.org>
"triple_r" <nomail@nomail> wrote:
> In general?  I would evaluate it on a sparse grid, then refine that guess with
> something like Powell's method or conjugate gradient.
>
> Here?  The maximum is at (1,0,0), and happens to be equal to 34.5012.
>
>  - Ricky

Thanks for your reply!

The maximum in this particular case can't be 34.5012, as plugging <1,0,0,> into
the function results in a value of 3.808.

I was hoping for a general method that I could apply anywhere, but I see now
that there could possibly be multiple maximums--or no maximum at all!--unless a
strict range were also given. This is not an issue in this case, however, since
the function is not continuous.

Through trial and error I came up with an equation that is pretty close (less
than 1% error in many cases), but is still in need of some work:

#declare max_value = pow(Blob_threshold,-pow(Blob_radius,2))/2 +
pow(Blob_threshold,-pow(Blob_radius,2))/2

-Mike


Post a reply to this message

From: Mike Williams
Subject: Re: How to find the maximum value of a function?
Date: 15 Nov 2008 07:18:51
Message: <CjdvfyC$xrHJFw0J@econym.demon.co.uk>
Wasn't it SharkD who wrote:
>I have defined a function (function "fn_E", below) and would like to determine
>a. the maximum possible value of the function, and b. the coordinates where the
>maximum occurs. How can I accomplish this?

The general solution to such problems is to differentiate the function 
and solve that to find places where the differential is zero. The 
maxima, minima and turning points of the original function are at places 
where the differential is zero.

In the general case, that would require 3D calculus, but your particular 
example is symmetrical in y/z so you can probably get away with assuming 
that you can find the maxima and maxima on the line z=x or z=-x, and 
thereby reduce it to two 2D cases.

The approach would be to express fn_D in terms of x, y, and z, rather 
than by referencing the earlier functions, then substitute z=x, 
differentiate and solve.

My calculus is a bit rusty (I think I last did any about 32 years ago) 
so I wouldn't fancy attempting it.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Dan Connelly
Subject: Re: How to find the maximum value of a function?
Date: 15 Nov 2008 09:04:13
Message: <491ed6dd@news.povray.org>
Numerical Recipes has a chapter on the topic.

Third Edition requires a subscription, or better, buy the book, which is a great read
if you like numerical methods.  But the second edition is on-line for free:
http://www.nrbook.com/a/bookcpdf.php

See chapter 10.

Dan


Post a reply to this message

From: triple r
Subject: Re: How to find the maximum value of a function?
Date: 15 Nov 2008 12:35:00
Message: <web.491f07d7c0004fc9ef2b9ba40@news.povray.org>
"SharkD" <nomail@nomail> wrote:
> "triple_r" <nomail@nomail> wrote:
> > In general?  I would evaluate it on a sparse grid, then refine that guess with
> > something like Powell's method or conjugate gradient.
> >
> > Here?  The maximum is at (1,0,0), and happens to be equal to 34.5012.
> >
> >  - Ricky
>
> Thanks for your reply!
>
> The maximum in this particular case can't be 34.5012, as plugging <1,0,0,> into
> the function results in a value of 3.808.

Oops.  Sorry -- must have made a typo plugging it into the old calculator...
End of a long week...

> I was hoping for a general method that I could apply anywhere, but I see now
> that there could possibly be multiple maximums--or no maximum at all!--unless a
> strict range were also given. This is not an issue in this case, however, since
> the function is not continuous.

That's why, ultimately, a grid may be the best way to get an estimate, but good
luck either way.  Hopefully your skills with addition and subtraction are
better than mine...

 - Ricky


Post a reply to this message

From: SharkD
Subject: Re: How to find the maximum value of a function?
Date: 16 Nov 2008 02:05:00
Message: <web.491fc5c2c0004fc9771596a90@news.povray.org>
I've worked things out in excel so that all I need to do is find the equation of
this curve:

http://img266.imageshack.us/img266/4454/curvepo9.png

Unfortunately, I can't figure out what kind of curve it is. It kind of looks
like a catenary.

-Mike


Post a reply to this message

From: SharkD
Subject: Re: How to find the maximum value of a function?
Date: 16 Nov 2008 02:45:01
Message: <web.491fceb2c0004fc97575d2b00@news.povray.org>
"SharkD" <nomail@nomail> wrote:
> I've worked things out in excel so that all I need to do is find the equation of
> this curve:
>
> http://img266.imageshack.us/img266/4454/curvepo9.png
>
> Unfortunately, I can't figure out what kind of curve it is. It kind of looks
> like a catenary.
>
> -Mike

This curve (a catenary) seems to fit the points fairly closely:

f(x) = 0.2 cosh(x / 0.76) + 0.2

-Mike


Post a reply to this message

From: SharkD
Subject: Re: How to find the maximum value of a function?
Date: 16 Nov 2008 03:00:01
Message: <web.491fd1f5c0004fc9a3b1deab0@news.povray.org>
"SharkD" <nomail@nomail> wrote:
> "SharkD" <nomail@nomail> wrote:
> > I've worked things out in excel so that all I need to do is find the equation of
> > this curve:
> >
> > http://img266.imageshack.us/img266/4454/curvepo9.png
> >
> > Unfortunately, I can't figure out what kind of curve it is. It kind of looks
> > like a catenary.
> >
> > -Mike
>
> This curve (a catenary) seems to fit the points fairly closely:
>
> f(x) = 0.2 cosh(x / 0.76) + 0.2
>
> -Mike

Woops! I forgot to scale the function properly. Here's a fixed version:

f(x) = 0.07 cosh(x / 0.28) - 0.07

-Mike


Post a reply to this message

From: SharkD
Subject: Re: How to find the maximum value of a function?
Date: 16 Nov 2008 05:50:00
Message: <web.491ffa8bc0004fc970a34be80@news.povray.org>
I think I've been going about things entirely the wrong way. I'm more confused
now than I was at the start... :(

-Mike


Post a reply to this message

Goto Latest 10 Messages Next 3 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.