5. Generating your own data

Instead of plotting experimental data, physicists often like to ``doodle'' with mathematical expressions. Sometimes it's an attempt to visualize a solution to some differential equation, to see if it makes sense; or it's a first step in finding the nulls of a complicated polynomial; possibly it's a quick way to look up a family of standard mathematical functions. Programs like maple or mathematica do these things extremely well, but in many cases physica has sufficient capabilities, and is much faster.

As an example, execute the following commands:

PHYSICA: x=[0:3*Pi:0.1]
PHYSICA: y=x**2*exp(-x)
PHYSICA: graph x,y

and you can see right away that the function has a maximum value of about 0.55 near The vector x was generated from 0 to three Pi in steps of 0.1, then we calculated y(x) using the standard Fortran syntax, and plotted y vs. x in the usual way. We can look for the zeroes of the first derivative, in this way:

PHYSICA: set lintyp 9
PHYSICA: graph\noaxes x,deriv(x,y,`interp')
PHYSICA: replot

where we stipulated that the numerical derivative be calculated using the method of interpolating splines. To see what other possibilities exist, use help facility to look up the description of the special function deriv().

Both the function and its derivative show up on the same plot:

PostScript file
Figure 2. A physicist's `doodle'. We plot here and its first derivative (the dotted line).
For the derivative, we set the line type (set lintyp) to something other than the default value of 0, the solid line type (use display lines to see what line types are available).

Numerical integration, differentiation, spline interpolation, a large library of special functions (would you like to know what the fourth-order Laguerre polynomial looks like? - try y=laguerre(4,x)) - these are all things that physica does with ease. It is pointless to try to provide you with a comprehensive list of its capabilities, this is what the manuals are for. Remember, you don't have to know all of physica commands, just get the feel for where things are in the manual, to be able to look them up quickly when needed. For example, the special functions known to physica are described in Chapter 7 of the Reference Manual.

Up: Table of contents Next: 6. Changing the default settings Previous: 4.4 Hardcopy