|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
|
|