# Creating a Graphical Display of MathScript Results

Version:

Use the MathScript plot functions to create a graphical 2D or logarithmic display of your MathScript results. You can only execute plot functions in the command section of the MathScript Console.

The following procedure demonstrates how to create a plot in the MathScript Console using a specific example. The example plots the sine and the cosine of the given values. The steps you need to take to complete your specific task might be different than the following steps.

1. Select View»More»Tools Launcher to open the Tools Launcher.
2. Click MathScript Console to open the MathScript Console.
3. Enter the following code in the command section of the MathScript Console to plot the sine and the cosine of the given values. Press Enter after every command.
x = [0:0.1:2*pi];
clfig;
xlimit([0;2*pi]);
ylimit([-1;1]);
xlabel('x axis');
ylabel('y axis');
grid('on');
plot(sin(x));
hold('on');
plot(cos(x));
legend('sin(x)', 'cos(x)');

The code creates the following plot.

The commands you entered complete the following actions:
• x = [0:0.1:2*pi]; creates an array with values from 0 to 2*pi in steps of 0.1. Prevent displaying the output of the values in the command window by finishing the command with a semicolon.
• clfig clears the current plot window. If no plot window exists, clfig creates a new plot window.
• xlimit and ylimit set the ranges of the x- and the y-scale.
• xlabel and ylabel label the axes.
• plot plots the curve.
• hold determines that the new cos(x) plot doesn't overwrite the existing sin(x) plot.
• legend creates a legend of the two plotted curves.