2 This file is to be run by the EXAMPLE command, and may not
4 The following are either acceptable lines to Maxima, or they are
5 two successive '&' characters
6 and then followed by the name of the section of examples, and then followed by
7 a sequence of Maxima forms, e.g.
9 '&'& topic (without the quotes)
11 /* This is a comment */
24 f1:2*x*(1-l1)-2*(x-1)*l2$
28 algsys([f1,f2,f3,f4],[x,y,l1,l2]);
31 algsys([f1,f2],[x,y]);
35 (2*x+1)^3=13.5*(x^5+1);
40 declare(h,antisymmetric);
45 append([y+x,0,-3.2],[2.5e20,x]);
65 atvalue(f(x,y),[x=0,y=1],a^2);
66 atvalue('diff(f(x,y),x),x=0,y+1);
67 printprops(all,atvalue);
68 diff(4*f(x,y)^2-u(x,y)^2,x);
74 atvalue(f(x,y),[x=0,y=1],a^2)$
75 atvalue('diff(f(x,y),x),x=0,y+1);
76 printprops(all,atvalue);
77 diff(4*f(x,y)^2-u(x,y)^2,x);
82 [2*x-(a-1)*y=5*b,a*x+b*y+c=0]$
83 augcoefmatrix(%,[x,y]);
87 bezout(a*y+x^2+1,y^2+x*y+b,x);
88 expand(determinant(%));
89 %-expand(resultant(a*y+x^2+1,y^2+x*y+b,x));
94 hessian(f):=block([dfxx,dfxy,dfxz,dfyy,dfyz,dfzz],
95 dfxx:diff(f,x,2),dfxy:diff(f,x,1,y,1),
96 dfxz:diff(f,x,1,z,1),dfyy:diff(f,y,2),
97 dfyz:diff(f,y,1,z,1),dfzz:diff(f,z,2),
98 determinant(matrix([dfxx,dfxy,dfxz],[dfxy,dfyy,dfyz],
101 hessian(x^3-3*a*x*y*z+y^3);
102 subst(1,z,quotient(%,-54*a^2));
103 f(x):=block([y,use_fast_arrays:false], local(a), y:4, a[y]:x, display(a[y]))$
107 ff(x):=block([y,a,use_fast_arrays:true], y:4, a[y]:x, display(a[y]))$
113 islinear(exp,var):=block([c],
114 c:bothcoef(rat(exp,var),var),
115 is(freeof(var,c) and c[1]#0))$
116 islinear((r^2-(x-r)^2)/x,x);
120 g(l):=catch(map(lambda([x],if x<0 then throw(x) else f(x)),l))$
126 cf([1,2,-3]+[1,-2,1]);
131 ev(%[1,2]/%[2,2],numer);
135 cf([1,2,-3]+[1,-2,1]);
143 ev(%[1,2]/%[2,2],numer);
147 'integrate(%e^(sqrt(a)*sqrt(y)),y,0,4);
148 changevar(%,y-z^2/a,z,y);
150 sum(a[k]*x^(N-1-k), k, 0, N - 1);
151 changevar(%, m = N - 1 - k, m, k);
154 a:matrix([3,1],[2,4]);
155 expand(charpoly(a,lambda));
156 (programmode:true,solve(%));
158 ev(a.%-lambda*%,%th(2)[1]);
161 solve([%th(2),%],[x1,x2]);
165 coeff(2*a*tan(x)+tan(x)+b=5*tan(x)+3,tan(x));
166 coeff(y+x*%e^x+1,x,0);
170 combine(a/x+b/x+a/y+b/y);
174 declare(h,commutative);
179 (sqrt(-4)+sqrt(2.25))^2;
185 content(2*x*y+4*x^2*y^2,y);
189 nonzeroandfreeof(x,e):=is(e#0 and freeof(x,e));
190 matchdeclare(a,nonzeroandfreeof(x),b,freeof(x));
191 defmatch(linear,a*x+b,x);
192 linear(3*z+(y+1)*z+y**2,z);
193 matchdeclare([a,f],true);
194 constinterval(l,h):=constantp(h-l)$
195 matchdeclare(b,constinterval(a))$
196 matchdeclare(x,atom)$
197 block(remove(integrate,outative),
198 defmatch(checklimits,'integrate(f,x,a,b)),
199 declare(integrate,outative))$
200 'integrate(sin(t),t,x+%pi,x+2*%pi)$
202 'integrate(sin(t),t,0,x)$
208 deftaylor(f(x),x^2+sum(x^i/(2^i*i!^2),i,4,inf));
209 taylor(%e^sqrt(f(x)),x,0,4);
213 delete(sin(x),x+sin(x)+y);
220 depends(f,[x,y],[x,y],t);
225 'diff(y,x,2)+'diff(y,z,3)*2+'diff(y,x)*x^2;
230 eqn1:'diff(f(x),x)='diff(g(x),x)+sin(x);
231 eqn2:'diff(g(x),x,2)='diff(f(x),x)-cos(x);
232 atvalue('diff(g(x),x),x=0,a);
234 desolve([eqn1,eqn2],[f(x),g(x)]);
241 diff(sin(x)+x^3+2*x^2,x);
242 diff(sin(x)*cos(x),x);
243 diff(sin(x)*cos(x),x,2);
246 'integrate(f(x,y),y,g(x),h(x));
260 for a:-3 thru 26 step 7 do ldisplay(a)$
262 for i:1 while i<=10 do s:s+i;
266 for p:1 unless p>7 do
267 (term:diff(term,x)/p,
268 series:series+subst(x=0,term)*x^p)$
272 for j:i step -1 thru 1 do
276 for i thru 10 do (guess:subst(guess,x,0.5*(x+10/x)),
277 if abs(guess^2-10)<0.00005 then return(guess));
278 for count:2 next 3*count thru 20
281 thru 10 while x#0 do x:0.5*(x+5/x)$
284 newton(f,guess):=block([numer,y],local(f,df,x,guess),
286 define(df(x),diff(f(x),x)),
287 do (y:df(guess), if y=0 then error(
288 "derivative at",guess,"is zero"),
289 guess:guess-f(guess)/y,
290 if abs(f(guess))<5.0e-6 then return(guess)))$
293 for f in [log, rho, atan] do ldisp(f(1.0))$
294 ev(concat(e,linenum-1),numer);
298 declare(l,scalar,[m1,m2,m3],nonscalar);
299 expand((1-l*m1).(1-l*m2).(1-l*m3));
305 dpart(x+y/z^2,1,2,1);
316 matrix([2,1-a,-5*b],[a,b,c]);
324 eliminate([exp3,exp2,exp1],[y,z]);
341 sin(x)+cos(y)+(w+1)^2+'diff(sin(w),w);
342 ev(%,sin,expand,diff,x=2,y=1);
344 'diff(y^2+x*y+x^2,x,2,y,1);
372 'integrate(f(x),x,a,b);
373 for i thru 5 do s:s+i^2;
385 /* declare(integrate,noun)$ */
388 f(y):=diff(y*log(y),y,2);
389 f(y):=''(diff(y*log(y),y,2));
390 ''(concat(c,linenum-1));
394 ''(concat(c,linenum-2));
403 ev(%e^x*sin(x)^2,exponentialize);
408 ev(%,x:1,numer)-ev(%,x:0,numer);
409 integrate(%e^x*sin(x)^2,x);
416 (1/(x+y)^4-3/(y+z)^3)^2;
418 expand(a.(b+c.(d+e)+f));
423 ev(a*(b+c)+a*(b+c)^2,expop:1);
433 factor(z^2*(x+2*y)-4*x-8*y);
434 x^2*y^2+2*x*y^2+y^2-x^2-2*x-1;
435 block([dontfactor:[x]],factor(%/36/(y^2+2*y+1)));
438 factor(x^3+x^2*y^2-x*z^2-y^2*z^2);
439 (x+2)/(x+3)/(x+b)/(x+c)^2;
443 ratsimp((x^5-1)/(x-1));
451 ev((x+1)*((u+v)^2+a*(w+z)^2),expand);
461 freeof(y,sin(x+2*y));
462 freeof(cos(y),"*",sin(y)+cos(x));
471 fullmapl("+",[3,[4,5]],[[a,1],[0,-1.5]]);
475 funcsolve((n+1)*f(n)-(n+3)*f(n+1)/(n+1)=(n-1)/(n+2),f(n));
486 ev(g(2*y+z,-0.5),y:7);
487 h(n):=sum(i*x^i,i,0,n);
489 t[n](x):=ratexpand(2*x*t[n-1](x)-t[n-2](x));
493 g[n](x):=sum(ev(x),i,n,n+2);
494 h(n,x):=sum(ev(x),i,n,n+2);
497 p[n](x):=ratsimp(1/(2^n*n!)*diff((x^2-1)^n,x,n));
498 q(n,x):=ratsimp(1/(2^n*n!)*diff((x^2-1)^n,x,n));
503 f[i,j](x,y):=x^i+y^j;
504 g(fun,a,b):=print(fun," applied to ",a," and ",b," is ",fun(a,b))$
505 g(f[2,1],sin(%pi),2*c);
514 put(%e,transcendental,type);
515 put(%pi,transcendental,type)$
516 put(%i,algebraic,type)$
517 typeof(x):=block([q], if numberp(x)
518 then return(algebraic),
520 then return(maplist(typeof,x)),
521 q:get(x,type), if q=false then
522 error("not numeric") else q)$
523 errcatch(typeof(2*%e+x*%pi));
534 gradef(f(x,y),x^2,g(x,y));
536 gradef(j(n,z),'diff(j(n,z),n),
537 j(n-1,z)-n/z*j(n,z))$
538 ratsimp(diff(j(2,x),x,2));
542 poly:1.0e-20*x^2-5.5*x+5.2e20;
543 errcatch(ev(%,x=1.0e20));
544 horner(poly,x),keepfloat;
549 fib[n]:=if n=1 or n=2 then 1 else fib[n-1]+fib[n-2];
553 eta(mu,nu):=if mu=nu then mu else if mu>nu then mu-nu else mu+nu;
555 eta(eta(7,7),eta(1,2));
556 if not 5>=2 and 6<=5 or 4+1>3 then a else b;
560 'integrate(sinh(a*x)*f(t-x),x,0,t)+b*f(t)=t^2;
562 linsolve([%],['laplace(f(t),t,s)]);
569 'limit(f(x)^g(x+1),x,0,minus);
574 test(f):=block([u],u:integrate(f,x),ratsimp(f-diff(u,x)));
578 integrate(sin(x)^3,x);
580 integrate(%e^x/(%e^x+2),x);
581 integrate(1/(x*log(x)),x);
582 integrate(sin(2*x+3),x);
583 integrate(%e^x*erf(x),x);
584 integrate(x/(x^3+1),x);
587 integrate(x^(5/4)/(x+1)^(5/2),x,0,inf);
588 gradef(q(x),sin(x^2));
589 diff(log(q(r(x))),x);
596 is(log(log(a+1)+1)>0 and a^2+1>2*a);
600 (a+b)^4*(1+x*(2*x+(c+d)^2));
604 (a+b)*(x+a+b)^2*%e^(x^2+a*x+b);
605 isolate(%,x),exptisolate:true;
609 lambda([x,y,z],x^2+y^2+z^2);
615 laplace(%e^(2*t+a)*sin(t)*t,t,s);
619 declare(g,lassociative);
621 g(g(a,b),g(c,d))-g(a,g(b,g(c,d)));
625 matchdeclare([a,a1,a2],true);
626 oneless(x,y):=is(x=y-1)$
627 let(a1*a2!,a1!,oneless,a2,a1);
628 let(a1!/a1,(a1-1)!),letrat;
629 letsimp(n*m!*(n-1)!/m),letrat;
630 let(sin(a)^2,1-cos(a)^2);
636 matchdeclare([a,a1,a2],true);
637 oneless(x,y):=is(x=y-1)$
638 let(a1*a2!,a1!,oneless,a2,a1);
639 let(a1!/a1,(a1-1)!),letrat;
640 letsimp(n*m!*(n-1)!/m),letrat;
641 let(sin(a)^2,1-cos(a)^2);
647 limit(x*log(x),x,0,plus);
648 limit((1+x)^(1/x),x,0);
663 linsolve([%th(3),%th(2),%],[x,y,z]),globalsolve;
667 listofvars(f(x[1]+y)/g^(2+a));
677 2*(a*log(x) + 2*a*log(y));
679 logcontract(log(sqrt(x+1)+sqrt(x)) + log(sqrt(x+1)-sqrt(x)));
684 map(lambda([u],partfrac(u,x)),x+1/(x^3+4*x^2+5*x+2));
685 map(ratsimp, x/(x^2+x)+(y^2+y)/y);
686 map("=",[a,b],[-0.5,3]);
690 matchdeclare(a,true)$
691 tellsimp(sin(a)^2,1-cos(a)^2)$
694 nonzeroandfreeof(x,e):=is(e#0 and freeof(x,e));
695 matchdeclare(a,nonzeroandfreeof(x),b,freeof(x));
696 defmatch(linear,a*x+b,x);
697 linear(3*z+(y+1)*z+y**2,z);
698 matchdeclare([a,f],true);
699 constinterval(l,h):=constantp(h-l)$
700 matchdeclare(b,constinterval(a))$
701 matchdeclare(x,atom)$
702 block(remove(integrate,outative),
703 defmatch(checklimits,'integrate(f,x,a,b)),
704 declare(integrate,outative))$
705 'integrate(sin(t),t,x+%pi,x+2*%pi)$
707 'integrate(sin(t),t,0,x)$
712 m:matrix([a,0],[b,1]);
719 matrix([a,b,c],[d,e,f],[g,h,i]);
729 declare(f,multiplicative);
734 x/(x-y)^2-1/(x-y)-f(x)/(x-y)^3;
737 ((a+b)^10*s^2+2*a*b*s+(a*b)^2)/(a*b*s^2);
739 multthru(a.(b+c.(d+e)+f));
747 'limit(f(x)^g(x+1),x,0,minus);
748 is(inpart(%,0)=nounify(limit));
763 nusum(n^4*4^n/binomial(2*n,n),n,0,n);
765 unsum(prod(i^2,i,1,n),n);
775 x^2*'diff(y,x) + 3*x*y = sin(x)/x;
777 ic1(soln1,x=%pi,y=0);
778 'diff(y,x,2) + y*'diff(y,x)^3 = 0;
780 ratsimp(ic2(soln2,x=0,y=0,'diff(y,x)=2));
781 bc2(soln2,x=0,y=1,x=1,y=3);
785 diff(exp(x^2+y)/(x+y),x,2);
814 'integrate(f(x),x,a,b)+x;
821 27*y^3+54*x*y^2+36*x^2*y+y+8*x^3+x+1;
827 2/(x+2)-2/(x+1)+1/(x+1)^2;
833 partition(2*a*x*f(x),x);
838 integrate(1/(x^3+2),x)$
845 (2*a^2-b)*cos(x+2*y)-(a*b+5)*sin(u-4*x);
850 poissimp(sin(x)^5+cos(x)^5);
855 rectform(sin(2*%i+x));
857 rectform(log(3+4*%i));
859 rectform((2+3.5*%i)^0.25),numer;
864 factor(poly_discriminant((x-a)*(x-b)*(x-c),x));
873 powerseries(log(sin(x)/x),x,0);
879 printprops(r,atomgrad);
884 product(x+i*(i+1)/2,i,1,4);
898 printprops(r,atomgrad);
904 expand(%*(sqrt(17)-4));
908 (log(x^2+x)-log(x))^a/log(x+1)^(a/2);
910 log(a^(2*x)+2*a^x+1)/log(a^x+1);
912 (%e^x-1)/(%e^(x/2)+1);
917 matrix([2,1-a,-5*b],[a,b,c]);
922 declare(g,rassociative);
924 g(g(a,b),g(c,d))-g(a,g(b,g(c,d)));
930 ((x-2*y)^4/(x^2-4*y^2)^2+1)*(y+a)*(2*y+x)/(4*y^2+x^2);
944 (4*x^3+10*x-11)/(x^5+5);
945 polymod(%),modulus:3;
950 ratexpand((2*x-3*y)^3);
951 (x-1)/(x+1)^2+1/(x-1);
957 sin(x/(x^2+x))=%e^((log(x)+1)^2-log(x)^2);
961 ((x-1)^(3/2)-(x+1)*sqrt(x-1))/sqrt(x-1)/sqrt(x+1);
963 x^(a+1/a),ratsimpexpons;
967 ratsubst(a,x*y^2,x^4*y^8+x^4*y^3);
968 1 + cos(x) + cos(x)^2 + cos(x)^3 + cos(x)^4;
969 ratsubst(1-sin(x)^2,cos(x)^2,%);
970 ratsubst(1-cos(x)^2,sin(x)^2,sin(x)^4);
977 ev(%th(2)^2,ratwtlvl:1);
981 (%i*v+u)/(f+%i*e)+%e^(%i*alpha);
986 realroots(x^5-x-1,5.0e-6);
992 residue(s/(s^2+a^2),s,a*%i);
993 residue(sin(a*x)/x^4,x,0);
997 resultant(a*y+x^2+1,y^2+x*y+b,x);
1001 integrate(1/(x^3+2),x)$
1007 union({a,b,1,1/2,x^2},{-x^2,a,y,1/2});
1009 maplist(numfactor,%);
1014 risch(x^2*erf(x),x);
1020 rootscontract(x^(1/2)*y^(3/2));
1021 rootscontract(x^(1/2)*y^(1/4));
1023 rootscontract(x^(1/2)*y^(1/4));
1024 rootscontract(x^(1/2)*y^(1/3));
1026 rootscontract(x^(1/2)*y^(1/4));
1027 rootscontract(x^(1/2)*y^(1/3));
1029 rootscontract(sqrt(sqrt(x+1)+sqrt(x))*sqrt(sqrt(x+1)-sqrt(x)));
1031 rootscontract(sqrt(sqrt(5)+5)-5^(1/4)*sqrt(sqrt(5)+1));
1037 scanmap(factor,expand(%th(2)));
1043 exp:k^2*n^2+k^2*m^2*n^2-k^2*l^2*n^2-k^2*l^2*m^2*n^2;
1046 scsimp(exp,eq1,eq2);
1047 exq:(k1*k4-k1*k2-k2*k3)/k3^2;
1050 scsimp(exq,eq3,eq4);
1054 solve(asin(cos(3*x))*(f(x)-1),x);
1055 solve(5^f(x)=125,f(x)),solveradcan;
1056 [4*x^2-y^2=12,x*y-x=2];
1070 /* a laplace transform */
1071 t^(1/2)*%e^(-a*t/4)*%e^(-p*t);
1073 /* a bessel function */
1074 t^(1/2)*%j[1](2*a^(1/2)*t^(1/2))*%e^(-p*t);
1080 sqfr(4*x^4+4*x^3-3*x^2-4*x-1);
1085 substinpart(d^2,%,2);
1086 substinpart(f1,f[1](x+1),0);
1090 subst(a,x+y,x+(x+y)^2+y);
1091 subst(-%i,%i,a+b*%i);
1093 subst(x=0,diff(sin(x),x));
1094 errcatch(ev(diff(sin(x),x),x=0));
1095 integrate(x^i,x),i=-1;
1096 errcatch(subst(-1,i,integrate(x^i,x)));
1097 matrix([a,b],[c,d]);
1098 subst("[",matrix,%);
1103 substpart(3/2,%,2,1,2);
1104 27*y^3+54*x*y^2+36*x^2*y+y+8*x^3+x+1;
1105 substpart(factor(piece),%,[1,2,3,5]);
1107 substpart(xthru(piece),%,[2,3]);
1108 substpart("+",%,1,0);
1109 ratsimp((k^2*x^2-1)*(cos(x)+eps)/(3*k+n[1])/(5*k-n[2]));
1111 substpart(ratsimp(piece),%,1,[1,2]);
1112 -substpart(-piece,%,1,1);
1113 a+b/(x*(y+(a+b)*x)+1);
1114 substpart(multthru(piece),%,1,2,1);
1118 sum(i^2+2^i,i,0,n),simpsum;
1119 sum(3^(-i),i,1,inf),simpsum;
1120 sum(i^2,i,1,4)*sum(1/i^2,i,1,inf),simpsum;
1125 declare(h,symmetric);
1130 matchfix("@{","@}");
1140 %th(2).u.%th(2).u.%;
1141 infix(".u.",100,100)$
1142 infix(".i.",120,120)$
1143 %th(5).u.%th(5).u.%;
1144 remove(".u.",operator)$
1145 errcatch(%th(7).u.%th(3));
1146 remove(["@{","@}",".i.",".u."],operator)$
1150 taylor(sqrt(1+a*x+sin(x)),x,0,3);
1152 taylor(sqrt(1+x),x,0,5);
1154 product((x^i+1)^2.5,i,1,inf)/(x^2+1);
1155 taylor(%,x,0,3),keepfloat;
1156 taylor(1/log(1+x),x,0,3);
1157 taylor(cos(x)-sec(x),x,0,5);
1158 taylor((cos(x)-sec(x))^3,x,0,5);
1159 taylor((cos(x)-sec(x))^-3,x,0,5);
1160 taylor(sqrt(1-k^2*sin(x)^2),x,0,6);
1161 taylor((1+x)^n,x,0,4);
1162 taylor(sin(x+y),x,0,3,y,0,3);
1163 taylor(sin(x+y),[x,y],0,3);
1164 taylor(1/sin(x+y),x,0,3,y,0,3);
1165 taylor(1/sin(x+y),[x,y],0,3);
1169 taylor(1+x,[x,0,3]);
1171 taylor(1+x+y+z,[x,0,3],[y,1,2],[z,2,1]);
1173 taylor(1+x+y+z,[x,0,3],[y,0,3],[z,0,3]);
1178 10*(1+%i)/(3^(1/3)+%i);
1179 ratdisrep(rat(%)),algebraic;
1181 a/(sqrt(2)+sqrt(3))+1/(a*sqrt(2)-1);
1182 ratdisrep(rat(%)),algebraic;
1187 matchdeclare(x,freeof(%i))$
1189 tellsimp(sin(%i*x),%i*sinh(x));
1190 trigexpand(sin(x+%i*y));
1193 tellsimp(0^0,1),simp:false;
1195 remrule("^",%th(2)[1]);
1196 tellsimp(sin(x)^2,1-cos(x)^2)$
1201 matchdeclare(a,true)$
1202 tellsimp(sin(a)^2,1-cos(a)^2)$
1208 matrix([2,1-a,-5*b],[a,b,c]);
1213 sin(%pi/12)+tan(%pi/6);
1219 diff(atanh(sqrt(x)),x);
1225 integrate(%th(3),x);
1229 sech(x)^2*sinh(x)*tanh(x)/coth(x)^2 + cosh(x)^2*sech(x)^2*tanh(x)/coth(x)^2
1230 + sech(x)^2*tanh(x)/coth(x)^2;
1232 ev(sin(x),exponentialize);
1233 taylor(sin(x)/x,x,0,4);
1234 ev(cos(x)^2-sin(x)^2,sin(x)^2=1-cos(x)^2);
1238 x+sin(3*x)/sin(x),trigexpand,expand;
1239 trigexpand(sin(10*x+y));
1243 -sin(x)^2+3*cos(x)^2+x;
1244 expand(trigreduce(%));
1245 declare(j,integer,e,even,o,odd);
1259 ((x+2)^20-2*y)/(x+y)^20+(x+y)^-19-x/(x+y)^20;
1264 zeroequiv(sin(2*x)-2*sin(x)*cos(x),x);
1265 zeroequiv(%e^x+x,x);
1266 zeroequiv(log(a*b)-log(a)-log(b),a);