Sunday, June 5, 2016

Maxima - Plotting

Maxima is also a powerful plotting application (for both 2D and 3D). In this article, I going to introduce you to commands plot2d and plot3d. Both functions are very similar concerning the needed inputs, consequently, all the example I'm going to show are about plot2d but can also be applied to plot3d. As input, it needs: the function you want to plot; the limits of the plot (for 2D, the x limit is mandatory, but not the y limit, but you can also specify it (it's interesting if you got infinite values at y)); and some options (color, logarithmic scale, line style, labels...). Let's see some examples.
We start by plotting the sinus functions:
There isn't complicated. There is the sin(x) argument as the function input (we could use another variable as phi or alpha, but you'll need to add it in the second input); and then the x range (minimum and maximum). Pi is a Maxima constant, that's why I used the "%" symbol just before, otherwise Maxima will interpret it as a new variable named pi. There are a lot of constants in Maxima, and when you want to refer to one of them, just add "%" before (and check in the online manual the constant actually exists). 
Let's continue with the same example:
 Here I've added some useful options: first, I've increased the x range by multiplying by 2 the inferior limit; I've also added the y range; I've added the color of the line; and the labels for both the X and Y axis.
 And for plotting multiples functions in the same image?
 The function plot2d also accepts a list of functions as first input. But you will need to adapt all your options: you will need two colors as there are two lines; and two legends, if I haven't added the legend option, the legend will be the function itself (it's very useful for large functions to avoid having the entire function as the legend).
 And for plot3d?
Same as plot3d, I'm not going to explain again the inputs.
And now a practical exercise:
 Plot a function and its corresponding Taylor series near to a given point and for a given grade.
This is a very interesting exercise, as now you will see how the Taylor series is more accurate as you increase the grade. The function to obtain the consecutive Taylor series, was yet done in a previous article (https://physicsisbeautiful.blogspot.fr/2016/06/loops-conditions.html), so let's do the plotting part. We will use the previously said function inside our plotting function.
And here the plotting function:
First, we stock the results of the taylor_grade_n() function into a list. Then we use the plot2d() function to plot the results, but in the functions input of plot2d we must also add the original function, this way we can see the difference between the original and the Taylor series. And the last argument is that we disable the legend, as the higher grade of the Taylor series will be a large function. We could have done a legend with the grade of each function, but I let you doing this.









No comments:

Post a Comment