Upload
luciange
View
219
Download
0
Embed Size (px)
Citation preview
8/10/2019 Maxima Problem Solving
1/17
HomeAbout
Math BooksPrivacy PolicyTable of ContentsWrite for us
Applied MathEssential MathHistoryMath EducationMath NewsMath WebsitesSoftwareSuggested ReadingTutorialUnsolved Problems
A 10 minute tutorial for solving Mathproblems with Maxima
Posted by Antonio Cangiano in Essential Math, Softwareon June 4th, 2007 | 134responses
About 50,000 people read my article 3 awesome free Math programs. Chances are thatat least some of them downloaded and installed Maxima. If you are one of them but arenot acquainted with CAS (Computer Algebra System) software, Maxima may appear verycomplicated and difficult to use, even for the resolution of simple high school or calculusproblems. This doesnt have to be the case though, whether you are looking for moremath resourcesto use in your career or a student in an online bachelors degree in mathlooking for homework help, Maxima is very friendly and this 10 minute tutorial will getyou started right away. Once youve got the first steps down, you can always look up thespecific function that you need, or learn more from Maximas official manual.Alternatively, you can use the question mark followed by a string to obtain in-linedocumentation (e.g. ? integrate). This tutorial takes a practical approach, where simpleexamples are given to show you how to compute common tasks. Of course this is just thetip of the iceberg. Maxima is so much more than this, but scratching even just thesurface should be enough to get you going. In the end you are only investing 10 minutes.
Maxima as a calculator
You can use Maxima as a fast and reliable calculator whose precision is arbitrary withinthe limits of your PCs hardware. Maxima expects you to enter one or more commandsand expressions separated by a semicolon character (;), just like you would do in manyprogramming languages.
(%i1) 9+7;
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
1 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
2/17
(%o1)
(%i2) -17*19;
(%o2)
(%i3) 10/2;
(%o3)
Maxima allows you to refer to the latest result through the % character, and to anyprevious input or output by its respective prompted %i (input) or %o (output). For
example:
(%i4) % - 10;
(%o4)
(%i5) %o1 * 3;
(%o5)
For the sake of simplicity, from now on we will omit the numbered input and outputprompts produced by Maximas console, and indicate the output with a => sign. Whenthe numerator and denominator are both integers, a reduced fraction or an integer valueis returned. These can be evaluated in floating point by using thefloatfunction (or bfloatfor big floating point numbers):
8/2;=>
8/2.0;
=>
2/6;
=>
float(1/3);
=>
1/3.0;
=>
26/4;
=>
float(26/4);=>
As mentioned above, big numbers are not an issue:
13^26;
=>
13.0^26
=>
30!;
=>
float((7/3)^35);
=>
Constants and common functions
Here is a list of common constants in Maxima, which you should be aware of:
%e Eulers Number%pi
%phi the golden mean ( )
%i the imaginary unit ( )inf real positive infinity ( )minf real minus infinity ( )
infinity complex infinity
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
2 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
3/17
We can use some of these along with common functions:
sin(%pi/2) + cos(%pi/3);
=>
tan(%pi/3) * cot(%pi/3);
=>
float(sec(%pi/3) + csc(%pi/3));
=>sqrt(81);
=>
log(%e);
=>
Defining functions and variables
Variables can be assigned through a colon : and functions through :=. The followingcode shows how to use them:
a:7; b:8;
=>
=>sqrt(a^2+b^2);
=>
f(x):= x^2 -x + 1;
=>
f(3);
=>
f(a);
=>
f(b);
=>
Please note that Maxima only offers the natural logarithm function log. log10is notavailable by default but you can define it yourself as shown below:
log10(x):= log(x)/log(10);
=>
log10(10)
=>
Symbolic Calculations
factorenables us to find the prime factorization of a number:
factor(30!);
=>
We can also factor polynomials:
factor(x^2 + x -6);
=>
And expand them:
expand((x+3)^4);
=>
Simplify rational expressions:
ratsimp((x^2-1)/(x+1));=>
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
3 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
4/17
And simplify trigonometric expressions:
trigsimp(2*cos(x)^2 + sin(x)^2);
=>
Similarly, we can expand trigonometric expressions:
trigexpand(sin(2*x)+cos(2*x));
=>
Please note that Maxima wont accept 2x as a product, it requires you to explicitlyspecify 2*x. If you wish to obtain the TeX representation of a given expression, you canuse the texfunction:
tex(%);
=> $$-\sin ^2x+2\,\cos x\,\sin x+\cos ^2x$$
Solving Equations and Systems
We can easily solve equations and systems of equations through the function solve:
solve(x^2-4,x);
=>
%[2]
=>
solve(x^3=1,x);
=>
trigsimp(solve([cos(x)^2-x=2-sin(x)^2], [x]));
=>
solve([x - 2*y = 14, x + 3*y = 9],[x,y]);
=>
2D and 3D Plotting
Maxima enables us to plot 2D and 3D graphics, and even multiple functions in the samechart. The functions plot2dand plot3dare quite straightforward as you can see below.The second (and in the case of plot3d, the third) parameter, is just the range of values forx (and y) that define what portion of the chart gets plotted.
plot2d(x^2-x+3,[x,-10,10]);
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
4 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
5/17
plot2d([x^2, x^3, x^4 -x +1] ,[x,-10,10]);
f(x,y):= sin(x) + cos(y);
plot3d(f(x,y), [x,-5,5], [y,-5,5]);
Limits
limit((1+1/x)^x,x,inf);
=> %limit(sin(x)/x,x,0);
=>
limit(2*(x^2-4)/(x-2),x,2);
=>
limit(log(x),x,0,plus);
=>
limit(sqrt(-x)/x,x,0,minus);
=>
Differentiation
diff(sin(x), x);
=>diff(x^x, x);
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
5 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
6/17
=>
We can calculate higher order derivatives by passing the order as an optional number tothe diff function:
diff(tan(x), x, 4);
=>
Integration
Maxima offers several types of integration. To symbolically solve indefinite integrals useintegrate:
integrate(1/x, x);
=>
For definite integration, just specify the limits of integrations as the two last parameters:
integrate(x+2/(x -3), x, 0,1);
=>
integrate(%e^(-x^2),x,minf,inf);
=>
If the function integrateis unable to calculate an integral, you can do a numericalapproximation through one of the methods available (e.g. romberg):
romberg(cos(sin(x+1)), x, 0, 1);
=> 0.57591750059682
Sums and Products
sumand productare two functions for summation and product calculation. The simpsum
option simplifies the sum whenever possible. Notice how the product can be use todefine your own version of the factorial function as well.
sum(k, k, 1, n);
=>
sum(k, k, 1, n), simpsum;
=>
sum(1/k^4, k, 1, inf), simpsum;
=>
fact(n):=product(k, k, 1, n);=>
fact(10);
=>
Series Expansions
Series expansions can be calculated through the taylormethod (the last parameterspecifies the depth), or through the method powerseries:
niceindices(powerseries(%e^x, x, 0));
=>
taylor(%e^x, x, 0, 5);
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
6 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
7/17
=>
The truncmethod along with plot2dis used when taylors output needs to be plotted (todeal with the in taylors output):
plot2d([trunc(%), %e^x], [x,-5,5]);
I hope youll find this useful and that it will help you get started with Maxima. CAS canbe powerful tools and if you are willing to learn how to use them properly, you will soondiscover that it was time well invested.
Sponsors message: Math Better Explainedis an insightful ebook and screencast seriesthat will help you deeply understand fundamental mathematical concepts, and see math
in a new light. Get it here.
Possibly related articles:
3 awesome free Math programs1.Refresh your High School Math skills2.
What kind of Math did they teach you?3.
If you enjoyed this post, then make sure you subscribeto our Newsletterand/or RSS Feed.
134 Responses to A 10 minute tutorial for solving Math problems
with Maxima
Alex says:September 11, 2009 at 10:14 am
HiIm alex..I write because I knew Maxima last year and using there in linux, its
1.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
7 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
8/17
amazing!!!..But now I want install Maxima in WinXP (for work) and I fail theconfiguration because there is a problem with a socket!!!How Can I do?thanks (Sorry for my English)!!!Bie!!!
Reply
Hank says:September 20, 2009 at 1:08 am
Hi
Dont forget to check out the best Maxima tutorial IMHO:
http://www.csulb.edu/~woollett/
Cheers!
Reply
2.
Larry Dickson says:September 25, 2009 at 2:06 pm
How do you gracefully exit the maxima program? exit; and quit; dont work. I tried ?quit and did get out via a stack overflow but surely there is some way out otherthan crashing???
Reply
3.
Antonio Cangiano says:September 25, 2009 at 2:28 pm
Larry, quit(); will exit maxima.
Reply
4.
Alexandros says:
September 26, 2009 at 6:06 am
I exit maxima with Ctrl-D.
Reply
5.
samuel measho says:October 14, 2009 at 3:07 pm
HI ,I just want to ask how can i use maxima to compute and draw the graph ofcomplex numbers.
Reply
6.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
8 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
9/17
David Friedman says:October 16, 2009 at 4:22 pm
Im trying Maxima now, after closing my sage session. I ran into trouble using sageto define a symbolic sum e.g. you want to define a function like:
f(x) = sum(i, i, 1, x);
apparently sage cannot do that at this point in the development. It wasdisappointing that sage couldnt do this (or if it is possible to do this I couldntfigure it out after an hour of trying).
sage is actually the first hit after a google search for sage, so it is still popular,and maybe itll improve by leaps and bounds, but at least after the first ten minutesI have a better feeling about Maxima.
when I was searching for a way to solve my problem I found this thread, which
indicatesthat this functionality is on the way for the sage:
http://groups.google.com/group/sage-support/browse_thread/thread/cf9cb4e92ce3bc04/f5e41d8aa31294e4?lnk=gst&q=sum#f5e41d8aa31294e4
it seems to me that sage is more of an interface to or a concatenation of a lot ofother programs (latex, r, maxima, python etc., and also commercial programs likemathematica, matlab). I guess one has to ask whether when doing a task it is betterto use sage as a single command center, or to just use that program directly.
Reply
paulb says:September 12, 2011 at 10:37 pm
try
f(x):=sum(i, i, 1, x);plot2d(f(x),[x,1,20]);
Reply
7.
Rob says:November 14, 2009 at 6:31 pm
When I try your example:
trigsimp(2*cos(x)^2 + sin(x)^2);
I get=> \displaystyle \cos(x)^2+1instead of
=> \displaystyle \cos ^2x+1
8.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
9 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
10/17
Reply
jerzysays:March 10, 2012 at 3:44 pm
Maxima gives correct result, because:
2*cos(x)^2 + sin(x)^2=cos(x)^2+cos(x)^2 + sin(x)^2=cos(x)^2+1
wherecos(x)^2 + sin(x)^2=1
Reply
Ivan Belash says:
December 16, 2009 at 4:20 am
You forget one, but very important thing: how to run Ctrl+RIt really easy, but it was a problem for me.
Reply
9.
AKE says:February 22, 2010 at 2:41 pm
Very nice tutorial introduction! Highly recommended first intro to Maxima.
Ive put together a selection of the Maxima resources that Ive found most usefulover the years, including a succinct instruction cheatsheet, a guide to programmingsubroutines/scripts, and a Mathematica-Maxima syntax conversion chart.
Theyre available here:http://mathscitech.org/articles/maxima
Enjoy!
Reply
10.
A Rubens de Castro says:March 24, 2010 at 6:47 am
I am using wxMaxima on Ubuntu9.10.I understand that wxMaxima is just a front-end, the Maxima Kernel does not exist inmy computer, it resides somewhere else.All the examples you give are very easy, howeverI have a problem not covered on your tutorial: after a given number of operations(computations, writes to disk, etc) my connection with Maxima is terminated, it islike a time-out. Then I have to click on Restart Maxima to go on with mycalculations for some other value of the parameters.Anything obvious which I should but am not doing ??? My colleagues say Maxima
11.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
10 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
11/17
works better than Mathematica !
A Rubens
Reply
Alexandersays:April 23, 2010 at 12:19 pm
I am recently retired and cut my math curious teeth with Mathematica forstudents circa fall 2000. The past ten years i have developed computer parametricgeometry to explor gravity curves and have a written manuscript that would workbest with a symbolic logic program such as Derive or Mathematica in the backcover. TI didt want to look at it (Derive had more then enough power to studysimple curvature relations) and Mathematica never replied. I know it would pusheducation of math beyond expectations simply because I had so much fun doing it.Can any one out there help get this project air borne. Not in education I had noidea Maxima or others existed and there is little difference betwixt utility gained!Thanks for the tutorial and I will attempt the download and application.
Reply
12.
Ricardo Msays:August 24, 2011 at 5:27 pm
Men necesito un gran favor! necesito saber si sabes resolver problemas deoptimizacion lineal con este programa, se lo agradeceria mucho!
Reply
13.
synhedionn says:September 6, 2011 at 6:49 am
Hi,In Maxima: sum(i,i,1,n); gives sum(i,i,1,n);Cant it give n(n+1)/2?
Reply
Antonio Cangiano says:September 6, 2011 at 6:56 am
sum(i, i, 1, n), simpsum;
Reply
14.
Ragbir Chana says:November 11, 2011 at 9:39 am
Great tutorial. I like tutorials doing by example.
15.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
11 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
12/17
Reply
Derek Pilous says:March 5, 2012 at 5:52 pm
Fantastic tutorial, thank you very much. If youre not a teacher, you should be (well,
if youre scientist, youre excused ;)). I am teacher myself and I can say, there arefew people capable of writing so comprehensible and yet inspiring introduction totopic. Sorry for my English
Reply
16.
jerzysays:March 10, 2012 at 3:53 pm
Clear, simple, useffull, beautiful work. Thanks.
Reply
17.
RockyRoad says:April 3, 2012 at 6:31 am
Great work Antonio, thank you very much
Inspiring ? Yes !
Im nearly new to CAS programs (played a bit with gnuplot though), my last math
classes are over 25 years old now not easy !
Im delighted to discover what Maxima can do for me and feel eager to refresh andand expand my math notions and practice.
Your tutorial could do that !
Reply
18.
M Kanagasabapathysays:May 6, 2012 at 1:57 am
Dear Antonio Cangiano,
Excellent and Nice tutorial. Kindly proceed for higher computations , tensors,numerical simulations etc., if possible. It can be beneficial for researchers andstudents.Dr M Kanagasabapathy
Reply
19.
phobos says:
May 8, 2012 at 7:07 am
20.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
12 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
13/17
How to use if condition inside for loop.I am using the following:
new:makelist(0);k:1;for i from 1 thru 10 do ((if(imagpart(xvals[i]) = 0) then ab:makelist(xvals[i]),new:append(new,ab),k:k+1)
);
But, the if condition also gets executed 10 times.. though clearly it is not the case inmy program.
Reply
KSO says:May 8, 2012 at 8:38 pm
Im trying to add random noise to a function, but the random() function only
generates a single number, giving me an offset. I want my function to plot aLorentzian curve, for example, but I want random white noise added to every point,not just one. I used the following function definition:
Lno(G,x0,x):=(r:random(x),1/%pi*(0.5*G)/((x-x0)^2+(0.5*G)^2)+r);
and tried another
Lnoi(G,x0,x):=1/%pi*(0.5*G)/((x-x0)^2+(0.5*G)^2)+random(1.2);
All I get is a smooth Lorentzian curve with a random offset when I plot using plot2d,not random noise at every point.
Does anyone know how to do this?
Reply
Kevin Gregson says:November 12, 2012 at 10:29 pm
If anyones still interested in plotting random noise, this works:plot2d(at(lambda([x],1/%pi*(0.5*G)/((x-x0)^2+(0.5*G)^2)+random(0.2)),[G=3,x0=0]),[x,1,5]);
Reply
21.
albert says:September 17, 2012 at 10:16 am
I think your introductory page is brilliant.
There is however one aspect that might be improved. You could draw slightly moreattention to the variables and the fact that they can contain any result. It took me a
22.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
13 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
14/17
whole day 1) to realise one can do:
a:1 ;b:2 ;a+b ;Or for that matter:s:factor(30!);
2*s;I dont propose to make your page longer! It is the careful selection of what ispresented that makes it so good. It would suffice to make variables slightly moreprominent in the examples.groetjes Albert
1) Admittedly before I knew your introduction.
Reply
Dante says:May 20, 2013 at 7:36 am
I dont know why wxMaxima doesnt solve my limit. I input the limit and it returnsthe same limit written with LaTeX :S I dont knwo what Im doing wrong.
This is the limit im trying to solve:
limit([ln(x^2+1)/((5*sen(x))+x)]+6,x,0);
Reply
23.
Ahmed Fasih says:June 28, 2013 at 1:02 pm
In case anybody wants to do vector (or matrix) math, heres a quick example on howto make them:
u : transpose(matrix([x, y, z]));v : transpose(matrix([a, b, c]));
Matrix/vector multiplication is done by the dot, ., syntax:
transpose(u) . v;
And of course you can do the usual symbolic manipulations:
diff(sqrt(transpose(u) . v), x);
Reply
24.
rendering spirals | Spirotaxis says:August 27, 2013 at 1:06 am
[] to re-derive this approximation formula for an Archimedean spiral rather than acircle. I read a tutorial on using wxMaxima, then created a worksheet to chugthrough the derivation. The spiral may be composed of an []
Reply
25.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
14 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
15/17
mahtab says:September 18, 2013 at 7:38 am
What is different between Maxima and other softwares such as Matlab and Scilab?
what is benefits and features of my called softwares?
Reply
26.
Huen Yeong Kong says:September 28, 2013 at 5:32 pm
I could not get Maxima to do the folling job:x:[a,b,c,d,e];y:[1,2,3,4,5];I want to assign a=1,b=2,c=3,d=4,e=5usingmap(x,y)it does not workCould someone show me how to do this?
Reply
27.
Was man in MATH-BLOG.COM lernen kann | Mathematik mit Maxima says:November 21, 2013 at 4:24 am
[] Quelle: http://math-blog.com/2007/06/04/a-10-minute-tutorial-for-solving-math-problems-with-maxima/[]
Reply
28.
Robert Dodiersays:July 6, 2014 at 11:22 pm
Hi, thanks for the great tutorial. By the way, what tools did you use to compose thisarticle? The fonts and coloring are very nice.
Reply
29.
Jim Mooneysays:August 27, 2014 at 1:43 am
I tried some other popular packages, and they didnt work properly for variousreasons. (One looked good but wouldnt paste, amd I dont need to do All thatretyping. Another threw errors. Others were horrible to install, especially forWindows.)
This worked great, and easily, to include graphing, out of the box.
Reply
30.
Older Comments
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
15 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
16/17
Leave a Reply
Name (required)
Mail (will not be published) (required)
Website
Submit Comment
Notify me of follow-up comments by email.
Notify me of new posts by email.
Join Our Mailing List
* indicates require
Email Address *
First Name
Subscribe
Recommended Math Books
Click here to see our math book list.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
16 din 17 09.11.2014 00:04
8/10/2019 Maxima Problem Solving
17/17
Search
Search
SponsorsAuthors
Antonio CangianoChris WaggonerDavid BinnerDr Michael Taylor (PhD, CPhys)Gregory TholeJessica CangianoJohn F. McGowan, Ph.D.Katherine StangeMarvin Ray BurnsMichael KoployTony McDaniel
Categories Select Category
Math Links
New BooksNot Even WrongPolymathematicsTechnical BloggingThe N-Category CafThe Unapologetic MathematicianZen and the Art of Programming
Copyright Math-Blog 2007 - 2014. All rights reserved.
A 10 minute tutorial for solving Math problems ... http://math-blog.com/2007/06/04/a-10-minute-tu...
17 din 17 09.11.2014 00:04