Almost any workflow involves computing results, and that's what Mathematica does—from building a hedge-fund trading website or publishing interactive engineering textbooks, to developing embedded image-recognition algorithms or teaching calculus.
Mathematica is renowned as the world's ultimate application for computations. But it's much more—it's the only development platform fully integrating computation into complete workflows, moving you seamlessly from initial ideas all the way to deployed individual or enterprise solutions.
MATHEMATICA TUTORIAL
Introduction to Manipulate
The single command Manipulate lets you create an astonishing range of interactive applications with just a few lines of input. Manipulate is designed to be used by anyone who is comfortable using basic commands such as Table and Plot: it does not require learning any complicated new concepts, nor any understanding of user interface programming ideas.
The output you get from evaluating a Manipulate command is an interactive object containing one or more controls (sliders, etc.) that you can use to vary the value of one or more parameters. The output is very much like a small applet or widget: it is not just a static result, it is a running program you can interact with.
This tutorial is designed for people who are familiar with the basics of using the Mathematica language, including how to use functions, the various kinds of brackets and braces, and how to make simple plots. Some of the examples will use more advanced functions, but it is not necessary to understand exactly how these work in order to get the point of the example.
Despite the length of this tutorial, it is only half the story. "Advanced Manipulate Functionality" provides further information about some of the more sophisticated features of this rich command.
Manipulate Is as Easy as Table
At its most basic, the syntax of Manipulate is identical to that of the humble function Table. Consider this Table command, which produces a list of numbers from one to twenty.
In[1]:= |
|
Out[1]= |
Simply replace the word Table with the word Manipulate, and you get an interactive application that lets you explore values of n with a slider.
In[2]:= |
|
Out[2]= | Play Animation ▪ |
If you are reading this documentation inside Mathematica, you can click and drag the slider to see the displayed value change in real time (meaning that it changes while you are dragging the slider, not just when you release it). If you are reading a static form of the documentation, you will see the slider moved to an arbitrary position. (By default, it starts out on the left side, but in the following examples the slider has typically been moved away from its initial position.)
In both Table and Manipulate, the form is used to specify an "iterator", giving the name of the variable and the range over which to vary it.
Of course the whole point of Manipulate (and Table for that matter) is that you can put any expression you like in the first argument, not just a simple variable name. Moving the slider in this very simple output already starts to give an idea of the power of Manipulate.
In[3]:= |
|
Out[3]= | Play Animation ▪ |
Again, if you are reading this in a static form you will have to trust that the graph changes in real time when the slider is moved.
Note that the slider has an extra icon next to it which, when clicked, opens a small panel of additional controls. Here, the panel from the previous example is opened.
Play Animation ▪ |
The panel allows you to see the numerical value of the variable, as well as set it in motion using the animation controls.
If you want to see the value of the variable without having to open the subpanel, you can add the option Appearance->"Labeled" to the variable specification. (Note the number displayed to the right of the plus sign, which is updated in real time as the slider is moved.)
In[4]:= |
|
Out[4]= | Play Animation ▪ |
This is also the first hint that Manipulate goes far beyond the relative simplicity of Table, both in its output and in the flexibility and range of what can be specified in the list of variables.
Just like Table, Manipulate allows you to give more than one variable range specification.
In[5]:= |
|
Out[5]= | Play Animation ▪ |
You can have as many variables as you like, including so many that a similar Table command would try to enumerate an unreasonably large number of entries.
Niciun comentariu:
Trimiteți un comentariu