','..','$myPermit') ?>
SYLLABUS Previous: 9.1 Typesetting with TEX
Up: 9 PROBLEM BASED LEARNING
Next: 9.3 Parameters and switches
Numerical schemes submitted from the Java window are automatically inserted in the JBONE source code (e.g. solution 2.01) and have first to be compiled on our server before you can download and execute them locally in your browser. This page introduces a limited number of Java commands you may need to carry out your assignments. More details concerning the JBONE applet can be found in the program tree, the name index and finally in the program listing. For a complete tutorial in Java programming, consult the excellent course from Sun Microsystems.
time=0 use the initial condition to initialize the
functions
f0[i], f[i],g[i]
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, or prevent your browser from using
the older version that is often stored in the browser data cache.
|
and computes the evolution of the variables and arrays defining 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
extend 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 PROBLEM BASED LEARNING Next: 9.3 Parameters and switches