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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With