MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: java method in NDsolveDavid Bailey,http://www.dbaileyconsultancy.co.uk

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62275] Re: java method in NDsolveDavid Bailey,http://www.dbaileyconsultancy.co.uk
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Sat, 19 Nov 2005 05:53:57 -0500 (EST)
  • References: <dlkc8k$pqa$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Pradeep Suresh wrote:
>  Hi,
> i have come across this general problem of implementing JAVA methods in 
> Mathematica solver commands wherein the java method does not understand 
> that its arguement is a variable that is manipulated by the solve 
> command in question. Specifically, i used a method written by me that 
> takes an integer arguement and returns that integer + 1.the method 
> itself works fine and has been tested in mathematica, however, when i 
> tried to use this method in one of the equations being solved by 
> NDSolve, i have problems. To illustrate,
> 
> function[23] gives 24.
> but when we have NDSolve[{y'[t]==function[t]*y+2, y[0]==1},{t,0,10}] 
> gives this error
> Java::argx1: Method named function defined in class MathLink was called 
> with an incorrect number or type of arguments. The argument was t.
> 
> which i interpret as a problem of mathematica not parsing the arguement 
> 't' as an integer but as a character.
> 
> i hope somebody has come across a similar problem and has overcome it. 
> This seems to be a very general problem and a serious shortcoming of 
> mathematica if not solvable.
> Plz help!
> Thanks in advance!
> 
Hello,

I think the point here is that the arguments to NDSolve are evaluated 
before the operation gets to work. This is normal and generally 
desirable. All you need to do is to ensure that your Java function is 
only called when it has a suitable argument - e.g. by wrapping the Java 
function thus:

wrapFunc[x_?NumberQ]:=javaFunction[x]

Using wrapFunc inside NDSolve, you will not get a spurious evaluation. 
BTW, your Java function should be written to accept a double argument.


David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Types in Mathematica
  • Next by Date: Re: Programmatic Search and Replace
  • Previous by thread: Mathematica Personal Grid Edition
  • Next by thread: Thanks to dave bailey and chris chiasson, NDsolve problem solved!