0

I have a system of nonlinear dynamics which I which to solve to optimality. I know how to do this in MATLAB, but I wish to implement this in JAVA. I'm for some reason lost in how to do it in Java.

What I have is following:
z(t) which returns states in a dynamic system.

z(t) = [state1(t),...,state10(t)]

The rate of change of this dynamic system is given by:

z'(t) = f(z(t),u(t),d(t)) = [dstate1(t)/dt,...,dstate10(t)/dt]

where u(t) and d(t) is some external variables that I know the value of. In addition I have a function, lets denote that g(t) which is defined from a state variable:

g(t) = state4(t)/c1

where c1 is some constant.

Now I wish to solve the following unconstrained nonlinear system numerically:

g(t) - c2 = 0

f(z(t),u(t),0)= 0

where c2 is some constant. Above system can be seen as a simple f'(x) = 0 problem consisting of 11 equations and 1 unkowns and if I where supposed to solve this in MATLAB I would do following:

[output] = fsolve(@myDerivatives, someInitialGuess);

I am aware of the fact that JAVA doesn't come with any build-in solvers. So as I see it there are two options in solving the above mentioned problem:
Option 1: Do it my-self: I could use numerical methods as e.g. Gauss newton or similar to solve this system of nonlinear equations. However, I will start by using a java toolbox first, and then move to a numerical method afterwards.

Option 2: Solvers (e.g. commons optim) This solution is what I am would like to look into. I have been looking into this toolbox, however, I have failed to find an exact example of how to actually use the MultiVariateFunction evaluater and the numerical optimizer. Does any of you have any experience in doing so?

Please let me know if you have any ideas or suggestions for solving this problem. Thanks!

SteewDK
  • 363
  • 1
  • 4
  • 14
  • 1
    Can you include what it means for z'(t) which is an array of 10 values to be 0 ? Java doesn't come with solving libraries, you need to implement these yourself. – Peter Lawrey Dec 20 '13 at 11:10
  • 2
    Since Java doesn't come with math solving libraries, then there are 2 (maybe 3) ways to handle it: 1. Download a library that has support for mathematics - maybe http://commons.apache.org/proper/commons-math/ comes in handy; 2. Mix matlab with java: you may want to take a look at http://www.mathworks.com/products/javabuilder/ and http://stackoverflow.com/questions/1607933/running-matlab-function-from-java; and 3. Do it by yourself –  Dec 20 '13 at 11:12
  • I think you would be best off doing a Google search for (say) "java nonlinear optimization" and ploughing through the search hits. – Stephen C Dec 20 '13 at 11:21
  • I have refined the questions now regarding the commons optim toolbox, which I already have looked into - but failed to implement. – SteewDK Dec 20 '13 at 11:22
  • @PeterLawrey z'(t)=0, means that the statevector z(t) should not change in value. – SteewDK Dec 20 '13 at 11:25
  • @SteewDK Does that means it is unsolvable if there is no time where all dimensions are zero for z'(t)? – Peter Lawrey Dec 20 '13 at 11:50
  • @PeterLawrey: Do I understand you question correct if you are asking what happens if t=0? The question is relevant because (what I did not tell you is that) you have an initial solution to your state vector z(t) = x_initial. I have an initial value but seek to solve the system f(z(t),u(t),0) = 0 and g(t)-c2 = 0. Simplified it means i have a function f'(x)=0, where x in the original problem is u. Rather complex, i know, but basically i wish to solve 11 non linear equations with 1 unknown in java. – SteewDK Dec 20 '13 at 12:00
  • Not t=0, what if z'(t) is never 0, would you look for a local minimum? – Peter Lawrey Dec 20 '13 at 12:09
  • @PeterLawrey, exactly! I am interested in searching for a minimum (the function is convex and quadratic so it is going to be a global minimum) within some pre difened tolerance, let's say 10^-6. – SteewDK Dec 20 '13 at 12:23
  • @PeterLawrey which is the same as solving the system with 11 nonlinear equations since this is the derivatives of the function. – SteewDK Dec 20 '13 at 12:30
  • Please refine your problem statement. What you have written above looks like a differential equation with boundary conditions, with hints towards an optimal control problem. What you were doing in Matlab and telling in the comments is an optimization problem. The only connection I see is that in optimal control, following the Pontryagin maximum principle, one updates the control by minimizing the Hamiltonian wrt. the control variables. Can you state the purely mathematical problem, without transformations for its solution? – Lutz Lehmann Dec 21 '13 at 08:45
  • @LutzL: Thank you very much for your thourough reply. I appreciate it very much! It is a control system, however, I am not looking to solve the control system. I am only interested in solving the initial state where t=0 and ensure steady state - hence all derivatives must be zero. Then as I see it is an unconstrained optimization problem. This should be possible to solve by f'(x)=0. I found this peace of Java code online: http://www.cc.gatech.edu/~jbrazelt/files/math_seminar.pdf This may solve the problem - but is more time consuming to implement compared to using a nonlinear solver. – SteewDK Dec 21 '13 at 12:12
  • Which means you have n+1 equations in n+1 variables. n of those equations are f(z,u,0)=0, and additionaly g(z)-c=0. If the derivative is available or easy to code, you can use Newtons method or a quasi-Newton method like Broyden or adjoint Broyden. I'm not acquainted with any library, but something is bound to exist. – Lutz Lehmann Dec 21 '13 at 12:42
  • @LutzL, once again thanks for your reply. You are correct and that is actually what my search is about. The derivatives are all available so its 'simply' solving the system with 11 nonlinear equations. thanks again! – SteewDK Dec 21 '13 at 15:05

1 Answers1

0

Please compare what your original problem looks like:


A global optimization problem

minimize f(y)

is solved by looking for solutions of the derivatives system

0=grad f(y) or 0=df/dy (partial derivatives)

(the gradient is the column vector containing all partial derivatives), that is, you are computing the "flat" or horizontal points of f(y).


For optimization under constraints

minimize f(y,u) such that g(y,u)=0

one builds the Lagrangian functional

L(y,p,u) = f(y,u)+p*g(y,u)  (scalar product)

and then compute the flat points of that system, that is

g(y,u)=0, dL/dy(y,p,u)=0, dL/du(y,p,u)=0

After that, as also in the global optimization case, you have to determine what the type of the flat point is, maximum, minimun or saddle point.


Optimal control problems have the structure (one of several equivalent variants)

minimize integral(0,T) f(t,y(t),u(t)) dt

such that y'(t)=g(t,y(t),u(t)), y(0)=y0 and h(T,y(T))=0

To solve it, one considers the Hamiltonian

H(t,y,p,u)=f(t,y,u)-p*g(t,y,u)

and obtained the transformed problem

y' = -dH/dp = g, (partial derivatives, gradient)
p' =  dH/dy, 
   with boundary conditions 
       y(0)=y0, p(T)= something with dh/dy(T,y(T)) 
u(t) realizes the minimum in v -> H(t,y(t),p(t),v) 
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • why is this accepted as an answer? It doesn't provide a solution. I am asking because I was looking to solve a non linear system myself. – Fierce82 Oct 06 '17 at 12:46