Interactive Manipulation

So far, we’ve been using the Wolfram Language in a question-answer way: we type input, and the language responds with output. But the language also lets you set up user interfaces where one can continually manipulate a variable. The function Manipulate works a lot like Table, except that instead of producing a list of results, it gives a slider to interactively choose the value you want.

Manipulate[Table[Orange,n],{n,1,5,1}]

Table[Table[Orange,n],{n,1,5,1}]

Manipulate[Column[{n,n^2,n^3}],{n,1,10,1}]

Table[Column[{n,n^2,n^3}],{n,1,10,1}]

Unlike Table, Manipulate isn’t limited to a fixed set of possible values. If you simply omit the step size in Manipulate, it’ll assume you want any possible value in the range, not limited to whole numbers.

Manipulate[Column[{n,n^2,n^3}],{n,1,10}]

It’s very common to have graphics that you want to adjust interactively.

Manipulate[BarChart[{1,a,4,2*a,4,3*a,1}],{a,0,5}]

Manipulate[PieChart[{1,a,4,2*a,4,3*a,1}],{a,0,5}]

Manipulate lets you set up any number of controls. You just give the information for each variable in turn, one after another.

Manipulate[Graphics[Style[RegularPolygon[n],Hue[h]]],{n,5,20,1},{h,0,1}]

There are many ways to specify controls for Manipulate. If you give a list of possible values, you’ll get a chooser or menu.

Manipulate[Graphics[Style[RegularPolygon[5],color]],{color,{Red,Yellow,Blue}}]

Manipulate[Style[value,color,size],{value,1,20,1},{color,{Black,Red,Purple}},{size,Range[12,96,12]}]

Make a Manipulate to show Range[n] with n varying from 0 to 100. »

Make a Manipulate to plot the whole numbers up to n, where n can range from 5 to 50. »

Make a Manipulate to show a column of between 1 and 10 copies of x. »

Make a Manipulate to show a disk with a hue varying from 0 to 1. »

Make a Manipulate to show a disk with red, green and blue color components varying from 0 to 1. »

Make a Manipulate to show digit sequences of 4-digit integers (between 1000 and 9999). »

Make a Manipulate to create a list of between 5 and 50 equally spaced hues. »

Make a Manipulate that shows a list of a variable number of hexagons (between 1 and 10), and with variable hues. »

Make a Manipulate that lets you show a regular polygon with between 5 and 20 sides, in red, yellow or blue. »

Make a Manipulate that shows a pie chart with a number of equal segments varying from 1 to 10. »

Make a Manipulate that gives a bar chart of the 3 digits in integers from 100 to 999. »

Make a Manipulate that shows n random colors, where n can range from 1 to 50. »

Make a Manipulate to display a column of integer powers with bases from 1 to 25 and exponents from 1 to 10. »

Make a Manipulate of a number line of values of x^n for integer x from 1 to 10, with n varying from 0 to 5. »

Make a Manipulate to show a sphere that can vary in color from green to red. »

Make a Manipulate to plot numbers from 1 to 100 raised to powers that can vary between −1 and +1. »

Make a Manipulate to display 1000 at sizes between 5 and 100. »

Make a Manipulate to show a bar chart with 4 bars, each with a height that can be between 0 and 10. »

Does Manipulate work the same on web, mobile and desktop?

Ultimately yes. But it can be significantly slower on the web and on some mobile systems, because every time you move a slider it has to communicate over the internet with a server to find out what to do. On desktop and some mobile systems, everything is happening right there, inside your computer or other device—so it’s very fast.

Can I make a standalone app out of a Manipulate?

Yes. To make a web app, for example, you just need to use CloudDeploy. We’ll talk about this in Section 36.

Can I use random numbers in Manipulate?

Yes, but unless you “seed” them with SeedRandom, the random numbers will be different every time you move a slider.

Tech Notes