Re: D and math, can you isolate this ?

2016-09-21 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:

The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)


Forget to say yesterday that actually the original equation is

x = pow(cos(angle), 0.25*c);
y = pow(sin(angle), 0.25*c);

But I couldn't use this form.


Re: D and math, can you isolate this ?

2016-09-21 Thread Nicholas Wilson via Digitalmars-d-learn

On Wednesday, 21 September 2016 at 08:21:29 UTC, Basile B. wrote:
On Wednesday, 21 September 2016 at 01:34:06 UTC, Nicholas 
Wilson wrote:

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:

[...]


So if we rearrange and take the logs of both sides and divide 
by c we get


2*log(1-y)/c = log(1-2^(-2/c))

and then that we have one occurrence of c on each side do an 
iterative back substitution to find the intersection given 
that you know for y=0.5 ,c = 2.
We used this method for finding voltages and currents in 
circuits with semiconductors.


Y is a floating point value. I think I'm gonna make a LUT for 
let's say 100 values to find the initial range where the result 
stands.


What does Y being float have to do with this? LUT is a good idea, 
a round number like 64 or 128 (or even 32) is probably better.


then do
g = 2*log(1-y);//constant
c(n+1) = g/log(1-2^(-2/c(n)))
where c(1) is a guess from the LUT.
the iteration should converge very fast.


Re: D and math, can you isolate this ?

2016-09-21 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 01:34:06 UTC, Nicholas Wilson 
wrote:

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:
I've recently started an easing/interpolation family of 
function in my D user library. It's based on something I know 
well since I've already used them in 2012 in a VST plugin 
called GrainPlot (RIP).


However for one of the function, I can't manage to get the 
inverse.


A function that's fully implemented:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L598
- f(x,c) = x*x*x - x*x*c + x*c;
- c(f(0.5)) = 4 * (y - 0.125));

Another:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L749
- f(x,c) = pow(x, c);
- c(f(0.5)) = log(y) / log(0.5));

The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)


So if we rearrange and take the logs of both sides and divide 
by c we get


2*log(1-y)/c = log(1-2^(-2/c))

and then that we have one occurrence of c on each side do an 
iterative back substitution to find the intersection given that 
you know for y=0.5 ,c = 2.
We used this method for finding voltages and currents in 
circuits with semiconductors.


Y is a floating point value. I think I'm gonna make a LUT for 
let's say 100 values to find the initial range where the result 
stands.


Re: D and math, can you isolate this ?

2016-09-20 Thread Nicholas Wilson via Digitalmars-d-learn

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:
I've recently started an easing/interpolation family of 
function in my D user library. It's based on something I know 
well since I've already used them in 2012 in a VST plugin 
called GrainPlot (RIP).


However for one of the function, I can't manage to get the 
inverse.


A function that's fully implemented:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L598
- f(x,c) = x*x*x - x*x*c + x*c;
- c(f(0.5)) = 4 * (y - 0.125));

Another:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L749
- f(x,c) = pow(x, c);
- c(f(0.5)) = log(y) / log(0.5));

The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)


So if we rearrange and take the logs of both sides and divide by 
c we get


2*log(1-y)/c = log(1-2^(-2/c))

and then that we have one occurrence of c on each side do an 
iterative back substitution to find the intersection given that 
you know for y=0.5 ,c = 2.
We used this method for finding voltages and currents in circuits 
with semiconductors.


Re: D and math, can you isolate this ?

2016-09-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 20, 2016 at 09:22:19AM -0700, H. S. Teoh via Digitalmars-d-learn 
wrote:
> On Tue, Sep 20, 2016 at 12:35:18PM +, Basile B. via Digitalmars-d-learn 
> wrote:
> [...]
[...]
> > Which means that I ask you if you can isolate c for
> > 
> > y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);
> > 
> > y is always f(0.5,c)
[...]
> That probably means the inverse cannot be expressed in terms of
> elementary functions. Probably the only thing you can do is to use
> some kind of numerical approximation, like some form of Newton's
> method or some such, to find the value of c.
[...]

It may be analytically very hard to solve this equation, but it's
probably not so hard to solve numerically. Based on the graph of the
equation produced by Wolfram Alpha, it seems that y must always lie
between 0 and 1, and that it has a horizontal asymptote at y=1.  At
around c=6 or thereabouts, y becomes very close to 1.  The value of c
for y=0.5 is approximately 2, so that seems like a good initial guess
for an iterative method.

So if y<0 or y>1, return NaN. If y=1, return +inf. Otherwise, use an
iterative method with a starting value of c=2. Because of the horizontal
asymptote at y=1, though, values of c much greater than 6 will probably
be quite inaccurate, so hopefully your application doesn't depend on the
exact value in that case!


T

-- 
Freedom of speech: the whole world has no right *not* to hear my spouting off!


Re: D and math, can you isolate this ?

2016-09-20 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 20 September 2016 at 16:22:19 UTC, H. S. Teoh wrote:
On Tue, Sep 20, 2016 at 12:35:18PM +, Basile B. via 
Digitalmars-d-learn wrote: [...]

The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)


I couldn't manage to solve it.  Nested exponentials are very 
nasty to invert. :-(  At first, I thought it might be solvable 
in terms of the Lambert W function (aka ProductLog) but I 
couldn't manage to get the equation into the right form.  Then 
I checked on Wolfram Alpha and it says "no result found in 
terms of standard mathematical functions".


That probably means the inverse cannot be expressed in terms of 
elementary functions. Probably the only thing you can do is to 
use some kind of numerical approximation, like some form of 
Newton's method or some such, to find the value of c.



T


Thanks for trying, you're not the first to tell me about the 
Newton's method...


Re: D and math, can you isolate this ?

2016-09-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 20, 2016 at 12:35:18PM +, Basile B. via Digitalmars-d-learn 
wrote:
[...]
> The problem is here:
> https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
> - f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
> - c(f0.5)) = ?
> 
> Which means that I ask you if you can isolate c for
> 
> y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);
> 
> y is always f(0.5,c)

I couldn't manage to solve it.  Nested exponentials are very nasty to
invert. :-(  At first, I thought it might be solvable in terms of the
Lambert W function (aka ProductLog) but I couldn't manage to get the
equation into the right form.  Then I checked on Wolfram Alpha and it
says "no result found in terms of standard mathematical functions".

That probably means the inverse cannot be expressed in terms of
elementary functions. Probably the only thing you can do is to use some
kind of numerical approximation, like some form of Newton's method or
some such, to find the value of c.


T

-- 
Questions are the beginning of intelligence, but the fear of God is the 
beginning of wisdom.


Re: D and math, can you isolate this ?

2016-09-20 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:
I've recently started an easing/interpolation family of 
function in my D user library. It's based on something I know 
well since I've already used them in 2012 in a VST plugin 
called GrainPlot (RIP).


However for one of the function, I can't manage to get the 
inverse.

[...]
The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)


If you don't understand, these function have a control point, for 
"parabol" and "pow" it's easy to get the c Coefficient that 
manages the slope. But for the ellipse (aka the super ellipse) 
it's a math nightmare )


For example is use the three functions in the same order 
(parabol, pow, ellipse):


http://sendvid.com/ygti5jmr

for the ellipse you can see that the mouse position is not in 
sync with the control point at the middle...it's the problem.


I need to isolate c when "y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c 
* 0.5)".

I know it's hard...otherwise I wouldn't ask ;]




D and math, can you isolate this ?

2016-09-20 Thread Basile B. via Digitalmars-d-learn
I've recently started an easing/interpolation family of function 
in my D user library. It's based on something I know well since 
I've already used them in 2012 in a VST plugin called GrainPlot 
(RIP).


However for one of the function, I can't manage to get the 
inverse.


A function that's fully implemented:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L598
- f(x,c) = x*x*x - x*x*c + x*c;
- c(f(0.5)) = 4 * (y - 0.125));

Another:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L749
- f(x,c) = pow(x, c);
- c(f(0.5)) = log(y) / log(0.5));

The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)