What compiler error do you get? If it does not like
the use of the inner class you can just use a normal
class:
class MyDyByDxFunction implements Mapping {
public double map(double y) {
return f(y);
}
}
then,
rungekutta(yValues, new MyDyByDxFunction(), dx);
The Mapping interface declares a method
double map(double).
This method is used to define the dy/dx function to be
used by rungekutta. So, any class which implements
Mapping can be passed to rungekutta.
What ODE are you trying to solve?
--- lydiacetin <lydiacetin@...> wrote: >
Thanks for your response Mark, but I'm having a
> little trouble
> implementing the code. My main problem is that I
> don't think I can
> use the func object in the parameters for the static
> rungeKutta4()
> method (the compiler won't let me anyway!!). Also,
> can you explain to
> me how the Mapping interface works
> Thanks
>
> Lydia
>
> --- In jsci@yahoogroups.com, Mark Hale
> <mj_hale@y...> wrote:
> >
> > Hi,
> >
> > Say you have a function dy/dt = f(y). Then, you
> would
> > do the following in code:
> >
> > // create inner class representing function
> > Mapping func = new Mapping() {
> > public double map(double y) {
> > return f(y);
> > }
> > };
> > int N = 50;
> > double dt = 0.1;
> > double[] yValues = new double[N]; // will contain
> y_i
> > yValues[0] = y0; // set initial condition
> > NumericalMath.rungeKutta(yValues, func, dt);
> > // can now plot yValues to see result
> >
> > I'll improve the docs for this.
> >
> > Regards,
> >
> > Mark
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor
>
>
> Yahoo! Groups Links
>
>
> jsci-unsubscribe@yahoogroups.com
>
>
>
____________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html