Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show plots inside module in Mathematica

I want to show plots inside a module (maybe recursive):

m = Module[{i, j}, i = 3; Plot[Sin[t], {t, 0, 1}]; j = 4]

Even

m = Module[{i, j}, i = 3; Show[Plot[Sin[t], {t, 0, 1}]]; j = 4]

not work. Why is this, and how to plot correctly?

like image 216
Qiang Li Avatar asked Dec 31 '11 06:12

Qiang Li


People also ask

What is Plot command in Mathematica?

The "Plot" command in MATHEMATICAThe basic command for sketching the graph of a real-valued function of one variable in MATHEMATICA is. Plot[ f, {x,xmin,xmax} ] which will draw the graph of y=f(x) over the closed interval [xmin,xmax] on the x-axis.

What is module command in Mathematica?

Module allows you to set up local variables with names that are local to the module. Module creates new symbols to represent each of its local variables every time it is called. Module creates a symbol with name xxx$nnn to represent a local variable with name xxx.


1 Answers

The only reason a plot is normally displayed in Mathematica is that the Plot function returns the graphics object representing the plot, and Mathematica displays the return value of whatever you run in a notebook. However, when you follow the statement with a semicolon, you prevent it from returning a value.

What you can do if you need to display something from within the middle of a module is Print[Plot[...]];. The Print function displays the value of its argument directly.

like image 116
David Z Avatar answered Sep 23 '22 12:09

David Z