The numerical schemes submitted from the Java window are automatically inserted in the VMARKET source code (e.g. solution 2.03) and compiled on our server before you can download them for execution locally in your browser. This section introduces a limited number of Java commands that will be useful when you carry out your assignments. More details concerning the VMARKET applet can be found in the program tree, the name index and finally in the program listing in the course environement. For a complete course in Java programming, consult the website from Sun Microsystems.
time=0
use the well known terminal payoff of a contract to
initialize functions
f0[i],f[i],g[i]
, the exact definition of which depend on the
specific problem.
f
(black curve), f0
(grey), and g
(blue).
fp
after a small time step in terms of present
f
and sometimes past values fm
.
time=time+timeStep
and the solution
arrays fm=f; f=fp
.
double scale = runData.getParamValue("UserDouble"); for (int i=0; i<=n; i++) { fp[i]=scale*f[i]; }executes an artificial evolution, where the next value
fp
is
obtained from a simple scaling of the present value f
.
Remember that you have to
force your browser to reload
the applet after each modification in order to prevent your browser from
using an older version of the applet that has been temporarily stored in
the browser data cache.
|
The evolution is then computed with the help of predefined arrays containing
the solution (an object called
solution)
|
Note that in Java (as in C and C++), the index of arrays starts with zero
(x[0]
) and finishes with an index lower by one element less than
its size (x[x.length-1]
).
/* the mistake dividing by zero has been commented out for debugging double error = fp[n]/0; */ System.out.println("Value fp["+i+"] = "+fp[i]);This example will print the values of the array
fp
to the
Java Console of your browser (with Netscape select
Communicator + Tools
+ Java Console,
with Explorer first select
Tool + Internet Options
+ Advanced
+ Java console enabled
and then View + Java Console).
From the values that are printed after a single step, it is possible to
track down most of the mistakes.
Another debuging strategy is to temporarily des-activate a portion of
your program, using the \* Java comment delimiters *\
that can
span over several lines.
new
int i = 3; // Declare i as an integer double[] c; // Declare c[] array 16 digits nbrs c = new double[i]; // Memory for c[0], c[1], c[2] BandMatrix A; // Declare A as a BandMatrix object A = new BandMatrix(3,10); // Memory for 3 bands with 10 doubles
c[0]
before the memory has been
attributed with a new
statement leads to the infamous
java.lang.NullPointerException
error; using c[3]
throws
an java.lang.ArrayIndexOutOfBoundsException:3
, since the array
is accessed outside its valid range 0,1,2.
=
whereas the comparing equal sign by a double ==
int a = 42; if (a == 17) System.out.println("a is equal to 17"); if (a != 17) System.out.println("a is not equal to 17");will print the text "
a is not equal to 17
" to the Java Console.
SYLLABUS Previous: 9.1 Typesetting with TEX Up: 9 LEARNING LABORATORY ENVIRONEMENT Next: 9.3 VMarket parameters and