420 likes | 468 Views
Plotting in Maxima. There are two packages currently used for plotting in Maxima. gnuplot xMaxima There may be some problems plotting if Maxima is not completely and correctly installed. We will use gnuplot most of the time. There are many ways to plot in Maxima.
E N D
There are two packages currently used for plotting in Maxima • gnuplot • xMaxima • There may be some problems plotting if Maxima is not completely and correctly installed. • We will use gnuplot most of the time.
There are many ways to plot in Maxima • Recall the function f(x) defined as SIN(x) * SQRT(1 + X^3) that we used in our spreadsheet example using Excel. We can plot this in Maxima, also.
One way to plot in Maxima: • Example: plot2d(sin(x)*sqrt(1 + x^3), [x, 1, 20]);
The Maxima system has an interface to the external gnuplot plotting software. • What’s gnu? • An effort of the free software foundation • The creator of the GNU General Public License
The GPL • The GNU Public license says, basically • You can use the software • You can copy it • You can bundle it commercially • You can sell it • You can sell services (installation, maintenance, etc.) • You can modify it, but …
The GPL • The GNU Public license says, basically • You can use the software • You can copy it • You can bundle it commercially • You can sell it • You can sell services (installation, maintenance, etc.) • You can modify it, but • You have to make the code available to anyone
We will use the GNU plotting routines almost exclusively • The next example, do the plot, but save it to a file. • What type of file? • jpg
We did plot2d(sin(x)*sqrt(1 + x^3), [x, 1, 20]; before – now save graph to a file. load(draw); plot2d(sin(x)*sqrt(1 + x^3), [x, 1, 20], [gnuplot_term, png], [gnuplot_out_file, "F:\sin-sqrt-graph.jpg"]);
How can we open it? • This can now be shared with any other application that can read jpg files. • A standard for scientific description of data.
Lets’ go over the syntax plot2d(sin(x)*sqrt(1 + x^3), [x, 1, 20], [gnuplot_term, png], [gnuplot_out_file, "F:\sin-sqrt-graph.jpg"]); • Code to print to a file is in teal color • Notice that everything inside the closing right parenthesis is delimited by square brackets [ and ]
What is delimited by [ and ] ? • Lists • Arrays • The Maxima evaluation software uses lists to indicate optional arguments
[gnuplot_term, png], [gnuplot_out_file, "F:\sin-sqrt-graph.jpg"]); • First term of the list is in red • It sets the value of the optional argument of gnuplot_term to png, for sending data
[gnuplot_term, png], [gnuplot_out_file, "F:\sin-sqrt-graph.jpg"]); • First term of the list is in red • It sets the value of the optional argument of gnuplot_term to png, for sending data • Second term of the list is in teal color • It sets the optional argument – the name of the output file, gnuplot_out_file, to"F:\sin-sqrt-graph.jpg"
gnuplot • Extremely powerful • Many options, probably too many to master completely • Use the examples here as a prototype for your work
Another graphing example • Plotting a discrete set of points
In Maxima: A : array(flonum, 20, 2); for i: 0 step 1 thru 19 do A[i,0]: i; for i : 0 step 1 thru 19 do A[i,1] :sin(i)* sqrt(1 + i ^3); We need flonum to provide floating point numbers to the graphics routine
Can do the two loops together as for i: 0 step 1 thru 19 do { A[i,0]: i , A[i,1] :sin(i)* sqrt(1 + i ^3) };
Now draw the points load(draw); C:/PROGRA~1/MAXIMA~1.1/share/maxima/5.18.1/share/draw/draw.lisp draw2d(points(A));
Let’s try some calculus f(x):= sin(x)*sqrt(1 +x^3)$ Now differentiate with respect to x g(x):=diff(f(x),x)$ Plot them both plot2d([f(x),g(x)] , [x,1,20]); Note the use of a list for f(x), g(x)
Where are the maxima and minima? • We can use Maxima to find the maxima (and minima) • Find the critical points – where the derivative is 0 • Remember – gnuplot tracks cursor position • Move the cursor to where the derivative appears to be 0 – these are the critical points (approximately)
Maxima can’t do everything • It can’t solve such general equations • Equation solving usually requires equations with algebraic functions only.