commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <Luc.Maison...@free.fr>
Subject Re: [math] Total derivative of a MultivariateVectorFunction
Date Sat, 25 May 2013 19:40:18 GMT
Le 25/05/2013 21:27, Luc Maisonobe a écrit :
> Hi Christoph,
> 
> Le 23/05/2013 10:39, Christoph Höger a écrit :
>> Am 22.05.2013 22:50, schrieb Luc Maisonobe:
>>
>>> I am not sure I understood your use case properly. I'll look at it further in
the next few days.
>>>
>>> A first very quick answer is that the interface as it is defined does not seem
to correspond to your needs.
>>> In the current interface, the meaning of the two "value" method is the same.
So the various elements in
>>> The point array should be the same. In your case, I think you already use the
array to represent derivatives
>>> of the first element, so I think you expanded the content of what should be a
single DerivativeStructure instance as a double array.
>>>
>>> Are you sure you should not use a univariate function ? The DerivativeStructure
argument you would get
>>> would contain all the partial derivatives already.
>>>
>>> Once again, I'm not sure I understood your example properly as I did not find
the time to think about it for now.
>>>
>>> Best regards,
>>> Luc
>>
>> Hi Luc,
>>
>> I am trying to motivate the problem:
>>
>> Consider the simple pendulum equation
>>
>> x² + y² - L² = 0
>>
>> I could use DerivativeStructure to solve for that equation by using e.g.
>> NewtonRaphson.
>>
>> But in a model, x and y are actually depending on the free variable t,
>> so I may require the total derivative of the above equation, e.g.:
>>
>> 2*x*dx + 2*y*dy = 0
>>
>> Again, I want to be able to solve for that equation by using an
>> iterative method. The thing is: This total derivative has now more
>> parameters than the original equation (namely dx and dy).
>>
>> If I model it that way, I can pass the x and y parameters to the base
>> function, evaluate the partial derivatives (2x and 2y) and multiply them
>> with the total derivatives dx and dy. The problem here is that the
>> base-equations partial derivatives are not constant (the second order
>> partial derivatives are, though). So I somehow need to reflect that for
>> the numerical solver. That's why I thought, I should make the derivative
>> also a MultivariateDifferentialFunction.
> 
> The differentiation framework does not mandate that the number of
> arguments of the Java method implementing the mathematical functions are
> equal. One parameter (say x for example) can be a function of another
> parameter (say t), or even a function of n different parameters x =
> f(p1, p2, p3, ..., pn). You do not even need to know the number of free
> variables when you use x, and the same code can be reused with x  being
> the free variable, x, being a function of one free variable t or x being
> a function of n free variables p1, ... pn. In all cases, whan you
> compute x * x the appropriate number of derivatives will be computed for
> you.
> 
> So I would suggest the following in your case: implement in the most
> straightforward way your function using a few intermediate functions.
> Let's say for example that x = a cos(t) and y = b sin(t) (i.e. you are
> working on an ellipse):
> 
> 
>       public DerivativeStructure x(DerivativeStructure t) {
>         return t.cos().multiply(a);
>       }
> 
>       public DerivativeStructure y(DerivativeStructure t) {
>         return t.cos().multiply(b);
>       }
> 
>       public DerivativeStructure f(DerivativeStructure x,
>                                    DerivativeStructure y) {
>         return x.multiply(x).add(y.multiply(y)).add(l * l);

Sorry, in the line above, replace .add(l * l) with .subtract(l * l),
otherwise the only solution would be x = 0, y = 0, and only of l is also
= 0 ...

>       }
> 
> When you want to solve f with respect to t, you would simply do
> 
>  UnivariateDifferentiableSolver solver =
>    new NewtonRaphsonSolver(absoluteAccuracy);
> 
>  UnivariateDifferentiableFunction func =
>     new UnivariateDifferentiableFunction() {
> 
>       public double value(double t) {
>         // not really used
>         return value(new DerivativeStructure(1, 0, t)).getValue();
>       }
> 
>       public DerivativeStructure value(DerivativeStructure t) {
>         return f(x(t), y(t));
>       }
> 
>     };
>  double tRoot = solver.solve(maxEval, func, min, max);
> 
> If on the other hand you need to optimize something using x and y
> as independent free variables, then you would set up a multivariate
> function as:
> 
>  MultivariateDifferentiableFunction func =
>     new MultivariateDifferentiableFunction() {
> 
>       public double value(double[] p) {
>         // not really used
>         return value(new DerivativeStructure[] {
>                        new DerivativeStructure(1, 0, p[0]),
>                        new DerivativeStructure(1, 0, p[1])
>                      }).getValue();
>       }
> 
>       public DerivativeStructure value(DerivativeStructure[] p) {
>         return f(p[0], p[1]);
>       }
> 
>     };
> 
> 
> There are two things to note.
> 
> The first one is that in both cases, you can reuse the same
> implementation of the function f. When called in the first case, it will
> be called with DerivativeStructure instances that will have one free
> variable (which is t) and differentiation order 1, so it will return a
> DerivativeStructure with the same structure and which will therefore
> contain two values: f and df/dt. When called in the second case, it will
> be called with DerivativeStructure instances that will have two free
> variables (which are x and y) and differentiation order 1, so it will
> return a DerivativeStructure with the same structure and which will
> therefore contain three values: f,  df/dx and df/dy. The f function
> adapts itself to the structure of its arguments and nothing in the code
> of the function knows about the number of free variables or order of
> derivation. In fact, if you call f with x and y each having hundreds of
> partial derivatives, then the result would have the same number of
> partial derivatives.
> 
> The second thing to note is a consequence of the first one: you don't
> explicitely write the total derivative 2*x*dx + 2*y*dy, it is implicitly
> computed directly by the framework.
> 
> Does this make sense to you?
> 
> Luc
> 
>>
>>
>>
>>
>>
>>
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message