Using maxima for high school mathematics




On Sun, 3 Apr 2011, Raymond Toy wrote:

< >>>>> "Daniel" == Daniel Dalton <daniel.dalton47 at gmail.com> writes:
< 
<     Daniel> 1) Is it possible with maxima to find the local minimums/maximums of a
<     Daniel> graph, along with the absolute/global minimum and maximum? I'm using the
<     Daniel> command line interface...
< 
< If you have a symbolic expression, can't you compute the derivative
< and use a numerical method to find the zeroes?  You can try solve or
< mnewton or minpack_solve to find the zeroes.
< 
<     Daniel> 2) When graphing with maxima, what is the best way to choose a suitable
<     Daniel> x range for the plot2d argument? Is it possible to mark the major points
<     Daniel> of my graphs (tp, min/max, end points, intercepts intersections etc.?)
<     Daniel> Is there anyway to permanently set some variables like gnuplot_term so I
<     Daniel> don't have to type so many arguments for the plot2d command? 
< 
< Look at set_plot_option.  You can set things like gnuplot_term there.
< 
<     Daniel> 3) Suppose I have 5 (x,y) coordinates. On the standard casio devices at
<     Daniel> school these points can be punched in and the user may trial a linear,
<     Daniel> quadratic or cubic equation to see which is the best fit for the
<     Daniel> points. The calculator provides a number of how successful the equation

Btw, a cubic always fits at least as good as a quadratic which fits in
turn at least as good as a linear model. If your calculator tells you a
linear model fits better than a cubic one, this is because it is using
some measuring stick other than goodness-of-fit. 

<     Daniel> was eg. linear, quadratic or cubic. Is it possible to find the equation
<     Daniel> for a set of points with maxima? 
< 
< Sure, but it looks like there's nothing completely builtin.  You can
< do a least-squares fit using lbfgs or minpack_lsquares to produce the
< equation.  But you'll have to set up the equations appropriately
< before calling these routines.

Here is a function that does the job, using the lsquares package.

(%i2) load(lsquares);

(%o2)
"/home/work/maxima/sandbox/git/maxima-git/share/contrib/lsquares.mac"

(%i3) lsqn(data,n):=block([poly,a,coeffs,x,est,mse,model],
            poly:sum(x^i*a[i],i,0,n),coeffs:delete(x,listofvars(poly)),
            est:lsquares_estimates(data,[x,y],y = poly,coeffs),
            model:subst(est[1],poly),
            mse:sum((data[i,2]-subst(x = data[i,1],model))^2,i,1,length(data))
                /length(data),
	   [model,mse])$

(%i4) data : genmatrix(lambda([x,y], if y=1 then x else
(1+2*x+3*x^2)),6,2);
 
(%o4) matrix([1,6],[2,17],[3,34],[4,57],[5,86],[6,121])

(%i5) lsqn(data,2);

(%o5) [3*x^2+2*x+1,0]

Leo 

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.