Records
Records
A data record is a group of data fields that are related.
A data field is for example an article number, article size,
production date etc.
In mathematics in particular, we are interested in the data
fields that we name in the analysis as a table of values. A value table assigns
a natural or real number with a constant difference between the numbers based
on the specified rule (function) to the respective pair of values.
We have already seen the representation of a function. Now
we would like to learn how to represent several functions in one coordinate
system.
A plotter can manage multiple records. Each data record has
its own values for color, drawing style, etc.
There are two ways of writing multiple functions in Java.
The first option is to call the "nextDataSet ()"
method. When this method is called, a new data record is automatically created
in Plotter. Subsequent calls to "add ()" are then automatically
assigned to this new data record. The disadvantage is that we have to specify
10 loops for 10 functions, which is why this option can be confusing.
for(double
x = -(Math.PI); x <= (Math.PI); x += 0.01) {
plotter.add(x, Math.sin(x));
}
plotter.nextDataSet();
for(double
x = -(Math.pi); x <= (Math.PI); x += 0.01) {
plotter.add(x, Math.cos(x));
}
The data records can be addressed directly for a more
compact solution. To do this you have to specify the name of the respective
function as a data record. The following can then be derived from the above
code.
In general, the following statements apply to the data
records:
- At the beginning, the internal counter is set to 0. The
associated data record applies, but is currently created after the first
access.
- If you use the "nextDataSet ()" method to switch
to a different data record, this other data record is considered to be current.
- If the "add ()" method is called without the
name, the current data record is used and with the "add ()" method
the value of the respective data record is assigned but is not seen as the
current data record.
- If a addressed data record does not yet exist, it will be
created.
- The saved data records are numbered and saved internally.
The first function begins with 0. The subsequent functions are given the next
larger integer as a position (the position must be free. Otherwise the next function
is simply given the next largest free integer.).
The names that we have defined as naming are irrelevant when
used. The names or names are only for the programmer and are for
simplification. If we only want to draw a function, we do not have to enter a
name.
A data record is represented internally by an instance of
the class “DataObject”.
It essentially consists of a sequence of pairs of values (x,
y). You can add or delete pairs of values using the following methods.
Method functionality
void add(double x, double y) appends
the pair of values (x, y)
void addD(double dx, double dy) (x + dx, y + dy) is added from the last
value (x, y).
void add(double[] feld) appends
all values from the given field
void removeOlt(int n) deletes
the first n values
In order to move all points of a data set together, offset
values can be set for the x and y directions. With the four methods, the
corresponding values can be set and queried again.
Later we will show this by being able to draw values offset
side by side several times.
There is a variant of all these methods with the name of the
data record as an additional parameter. Usually, however, the methods of the
"Plotter" class are sufficient for all access to the
"DataObject" instances.
Kommentare
Kommentar veröffentlichen