How to interpolate data in mathematica

Mathematica

What is Mathematica?

This question is answered in great detail in: Stephen Wolfram, Mathematica - A System for Doing Mathematics by Computer, 2nd edition, 1991, Addison-Wesley.

This book contains a detailed description of the syntax and hundreds of examples and is both an introduction to the handling and capabilities of the program and a reference work. At X-Terminals one can access the lexicon-like appendix of this book via the program "mathbook".

Mathematica is suitable ...

Possible forms of use:

  • interactive ()
  • via the Mathematica notebook ()
  • as a programming language
  • via program packages
  • linked to other programs

A first attempt (comments indented and in brackets):

prompt> math
(Mathematica is usually called with ''. The following lines then appear :)
Mathematica 2.2 for SGI Copyright 1988-93 Wolfram Research, Inc. - Motif graphics initialized -
(Mathematica is now started and ready to receive commands.)
In [1]: =
(This is what the 'prompt' of Mathematica looks like. All entries are automatically numbered from 1 upwards by Mathematica. You can later access old entries using these numbers. Type a command after the equal sign and finish the entry by pressing Enter Key. After that, this line could look something like this :)
In [1]: = 2 * 2
(Mathematica will now print the following :)
Out [1] = 4
(And be ready again for the next input. The outputs are also numbered exactly like the inputs and they can also be accessed later at any time.)
In [2]: = Plot [Sin [x], {x, 0.2 Pi}] Out [2] = -Graphics-
(Mathematica reports a graphical output and a new window appears showing the sine function from 0 to 2 Pi. And are functions that are available to the user immediately after starting Mathematica. Function names usually begin with an uppercase letter ; The arguments are enclosed in square brackets and separated by commas. Curly brackets, on the other hand, enclose lists of objects. Some mathematical constants such as Pi = 3.14159 ... are available to the user at the start; their names also begin with capital letters. Between ' 2 'and' Pi 'in curly brackets, the mal point () is omitted and replaced by a space, which is allowed in Mathematica.)
In [3]: =? Plot Plot [f, {x, xmin, xmax}] generates a plot of f as a function of x from xmin to xmax. Plot [{f1, f2, ...}, {x, xmin, xmax}] plots several functions fi. In [3]: =
(You can get information about functions by using "" followed by the name of the function. Such a command is not counted, which is why "" appears as prompt.)
In [3]: = ?? Plot Plot [f, {x, xmin, xmax}] generates a plot of f as a function of x from xmin to xmax. Plot [{f1, f2, ...}, {x, xmin, xmax}] plots several functions fi. Attributes [Plot] = {HoldAll, Protected} Options [Plot] = {AspectRatio -> GoldenRatio ^ (- 1), Axes -> Automatic, AxesLabel -> None, AxesOrigin -> Automatic, AxesStyle -> Automatic, Background -> Automatic , ColorOutput -> Automatic, Compiled -> True, DefaultColor -> Automatic, Epilog -> {}, Frame -> False, FrameLabel -> None, FrameStyle -> Automatic, FrameTicks -> Automatic, GridLines -> None, MaxBend -> 10., PlotDivision -> 20., PlotLabel -> None, PlotPoints -> 25, PlotRange -> Automatic, PlotRegion -> Automatic, PlotStyle -> Automatic, Prolog -> {}, RotateLabel -> True, Ticks -> Automatic, DefaultFont:> $ DefaultFont, DisplayFunction:> $ DisplayFunction} In [3]: =
(If you enter '' followed by the function name, you get even more detailed information in which, among other things, all options with which the function can be called are listed. The arrows behind the option name ('') refer to the current value of this Option. If you are looking for related functions or if you do not know the name of the function exactly, the use of wildcards ('') is recommended; the names of the commands that match the pattern '' then appear.)
In [3]: =? Plot * Plot PlotJoined PlotRange Plot3D PlotColor PlotLabel PlotRegion Plot3Matrix PlotDivision PlotPoints PlotStyle In [3]: = (You leave Mathematica with the command.) In [3]: = Quit

Examples of the use of Mathematica in numerical and symbolic calculations

In [1]: = N [Log [4 Pi]] Out [1] = 2.53102
(The function specifies the numerical value of the expression in brackets. The number of digits output can be changed using an option from :)
In [2]: = N [Log [4 Pi], 12] Out [2] = 2.53102424697
(An example of symbolic computing :)
In [3]: = Integrate [1 / x, x] Out [3] = Log [x]
(The indefinite integral of was calculated; the second argument of Integrate specifies the name of the variable to be used for integration. The function can be used to integrate numerically :)
In [4]: ​​= NIntegrate [1 / x, {x, 1.4 Pi}] Out [4] = 2.53102
(Mathematica has solutions for many common math problems; e.g. integration, differentiation, sums, series, solving equations of various kinds, solving systems of equations, and differential equations.)

(You can also define your own functions, for example :)

In [5]: = myfunction [x _]: = Log [x] * Sin [x]
(Here a new function with name has been defined. The underscore behind the x denotes a so-called function in Mathematica.'Pattern'; it means something like "Any expression can be used at this point".)
In [6]: = myfunction [1] Out [6] = 0 In [7]: = myfunction [2] Out [7] = Log [2] Sin [2] In [8]: = N [myfunction [2 ]] Out [8] = 0.630277
(Lists are an important type of object Mathematica works with. There are many commands for reading, creating, editing, and outputting lists. Example :)
In [9]: = Table [N [myfunction [v]], {v, 1,2,0.1}] Out [9] = {0, 0.0849411, 0.169931, 0.252803, 0.331576, 0.404449, 0.469803, 0.526205, 0.572415, 0.607386, 0.630277}
(With a list of values ​​of the function at the positions 1.0, 1.1, 1.2, ..., 2.0 was created. With you can display this table graphically :)
In [10]: = ListPlot [%, PlotJoined-> True] Out [10] = -Graphics-

Representation of functions and data

(Mathematica has many options for outputting functions and data; for example, in the form of lists and tables, 1, 2 or 3-dimensional graphics, which can also be colored and animated. Acoustic representations are also possible. Furthermore, codes can be output that are processed by other programs or compilers after minor additions (C, Fortran, TeX, PostScript). Here are some examples :)
In [1]: = Plot [{Sin [x], Sin [1.1 x], Sin [1.2 x]}, {x, 0, 2Pi}] Out [1] = -Graphics-
(As you can see you can output several functions at the same time, namely here, for example, the functions within the first curly bracket. In the second curly bracket, the variable (here: x) is named, and the interval on which the functions are displayed (here: [0.2 * Pi]). If you want to edit a graphical output, you can use the Show command :)
In [2]: = Show [Out [1], Frame-> True, GridLines-> Automatic, PlotLabel -> "Sinus curves"] Out [2] = -Graphics-
(With Show you can create an existing graphic with new options. There are a large number of options for the plot commands with which the graphics can be varied considerably.
Functions that depend on two variables can also be easily represented :)
In [3]: = Plot3D [Sin [x] Cos [y], {x, -Pi, Pi}, {y, -Pi, Pi}] Out [3] = -SurfaceGraphics-
(The command Plot3D is the equivalent of Plot for the case of two variables (here: x and y).)
In [4]: ​​= ContourPlot [Sin [x] Cos [y], {x, -Pi, Pi}, {y, -Pi, Pi}] Out [4] = -ContourGraphics-
(Again the same function, but here as a contour graph
(Lists and tables can be processed with Mathematica in a variety of ways. They can be read, manipulated and output, for example as graphics, but also as columns of numbers, matrices or something else. Let us assume that we are data in a file named " "have the following two columns:
1.3 3.7693 2.5 11.9825 2.6 14.0637 4.9 130.29 5.1 169.022
First we read this data from the file into a list called "list" :)
In [5]: = list = ReadList ["data", Number, RecordLists-> True] Out [5] = {{1.3, 3.7693}, {2.5, 11.9825}, {2.6, 14.0637}, {4.9, 130.29} , {5.1, 169.022}}
(With the function ListPlot this list can be represented graphically (see above). We want to logarithmize the second column of the list and assign the whole list to a variable which we call "logdat" :)
In [6]: = logdat = Table [{list [[i]] [[1]], Log [list [[i]] [[2]]]}, {i, 1, Length [list]}] Out [6] = {{1.3, 1.32689}, {2.5, 2.48345}, {2.6, 2.6436}, {4.9, 4.86976}, {5.1, 5.13003}}
(The following output format is a bit clearer :)
In [7]: = ColumnForm [logdat] Out [7] = {1.3, 1.32689} {2.5, 2.48345} {2.6, 2.6436} {4.9, 4.86976} {5.1, 5.13003}
(Now we want to write this output to a file called "logdaten" :)
In [8]: = Out [%] >> log data
(Finally we graph the logarithmized data set and output this graph as a PostScript file.)
In [9]: = ListPlot [logdat, PlotJoined-> True] Out [9] = -Graphics-
In [10]: = Display ["logdatengraph",%] Out [10] = -Graphics-
(With the last command a file called "logdatengraph" was created. With "psfix logdatengraph> logdatengraph.ps" you can create a file in PostScript format (outside of maths), which is then accepted as input by many printers.)
In [10]: = Quit

Modeling and analysis of data

You can use Mathematica to analyze and model data:
  • how is the data distributed?
  • how well can you describe them with a model?

It is planned to create further texts with tips and examples. However, this costs the authors a lot of (free) time. Therefore patience (or cooperation) is requested.


Content: Daniel Hoffmann, HTML formatting: Heiko Schlichting, February 7, 1994