# Maxima Code for Answers to the Exercises

 Exercise 1.

gr: (1+sqrt(5))/2;

float(gr);

reset()$kill(all)$

 Exercise 2.

gr: (1+sqrt(5))/2; ev(x^2-x-1,x=gr); %, numer;

reset()$kill(all)$

 Exercise 3.

solve(x^2-x-1=0,x);

reset()$kill(all)$

 Exercise 4.

(-1)^(1/3);

solve(x^3=-1,x);

reset()$kill(all)$

 Exercise 5.

ev(bfloat(%pi), fpprec:100);

reset()$kill(all)$

 Exercise 6.

ln: log;

reset()$kill(all)$

 Exercise 7.

log10(x):= float(log(x)/log(10));

log10(1000);

reset()$kill(all)$

 Exercise 8.

heron(a,b,c):= 0.25*sqrt((a^2+b^2+c^2)^2-2*(a^4+b^4+c^4));

reset()$kill(all)$

 Exercise 9.

? solve;

reset()$kill(all)$

 Exercise 10.

apropos("solve");

reset()$kill(all)$

 Exercise 11.

reset(); kill(all);

reset()$kill(all)$

 Exercise 12.

expand((a+b)^10);

reset()$kill(all)$

 Exercise 13.

factor(a^10-b^10);

factor(a^10+b^10);

reset()$kill(all)$

 Exercise 14.

ratsimp((a^10-b^10)/(a^2-b^2));

reset()$kill(all)$

 Exercise 15.

solve(x^2+2*(sin(alpha)+cos(alpha))*x+sin(2*alpha)+1=0, x);

trigexpand(%); trigsimp(%);

unique(%);

reset()$kill(all)$

 Exercise 16.

sgn(x):= if (x<0) then -1 else if (x=0) then 0 else 1;

sgn(-1); sgn(0); sgn(%pi);

reset()$kill(all)$

 Exercise 17.

assume(alpha>0,beta>0,alpha<1,beta<1,alpha+beta<1);

is(alpha>-1/2);

is(alpha> 1/2);

is(alpha> 1);

forget(alpha>0,beta>0,alpha<1,beta<1,alpha+beta<1);

reset()$kill(all)$

 Exercise 18.

numeric(x,prec):= ev(bfloat(x), fpprec:prec);

numeric(1/%e,30);

reset()$kill(all)$

 Exercise 19.

plot2d(1/sqrt(2*%pi)*exp(-x^2/2),[x,-3,3],[ylabel,"density"]);

reset()$kill(all)$

 Exercise 20.

plot2d([1/sqrt(2*%pi)*exp(-x^2/2), 1/(%pi*(1+x^2))], [x,-3,3], 
 [legend, "Gaussian distribution", "Cauchy distribution"], 
 [style, lines, [lines, 5]], [color, black, red], [ylabel,"density"]);

reset()$kill(all)$

 Exercise 21.

plot2d([1/x,1/x^2,1,x,x^2],[x,0,2],[y,0,2]);  

reset()$kill(all)$

 Exercise 22.

datalist: [[.25,-1.03], [.5,-0.63], [.75,-0.28], [1.,0.], 
 [1.25,0.22], [1.5,0.38], [1.75,0.47]];

plot2d([log(x), [discrete, datalist]], [x,0,2], [y,-2,1], 
 [style, lines, points], [point_type, diamond]);

reset()$kill(all)$

 Exercise 23.

plot2d([parametric, sin(4*%pi*t), cos(4*%pi*t)], 
 [t,0,4],[nticks,401]);

reset()$kill(all)$

 Exercise 24.

/*a*/ plot3d(1/(2*%pi)*exp(-0.5*(x^2+y^2)), [x,-3,3], [y,-3,3]);

/*b*/ plot3d(1/(2*%pi)*exp(-0.5*(x^2+y^2)), [x,-3,3], [y,-3,3], 
 [palette,false], [color, blue]);

/*c*/ plot3d(1/(2*%pi)*exp(-0.5*(x^2+y^2)), [x,-3,3], [y,-3,3], 
 [palette,false], [color, cyan, blue]);

/*d*/ plot3d(1/(2*%pi)*exp(-0.5*(x^2+y^2)), [x,-3,3], [y,-3,3], 
 [mesh_lines_color,false]);

reset()$kill(all)$

 Exercise 25.

load(draw)$

draw2d(ylabel="density", explicit(1/sqrt(2*%pi)*exp(-x^2/2), x,-3,3));

reset()$kill(all)$

 Exercise 26.

load(draw)$

draw2d(ylabel="density", 
 key="Gaussian distribution", color=black, 
 explicit(1/sqrt(2*%pi)*exp(-x^2/2), x,-3,3), 
 key="Cauchy distribution", color=red, line_width=5, 
 explicit(1/(%pi*(1+x^2)), x,-3,3));

reset()$kill(all)$

 Exercise 27.

load(draw)$

draw2d(yrange=[0,2], 
 key="1/x", color=blue, explicit(1/x, x,0,2), 
 key="1/x^2", color=red, explicit(1/x^2, x,0,2), 
 key="1", color=green, explicit(1, x,0,2), 
 key="x", color=magenta, explicit(x, x,0,2), 
 key="x^2", color=black, explicit(x^2, x,0,2));

reset()$kill(all)$

 Exercise 28.

load(draw)$

datalist: [[.25,-1.03], [.5,-0.63], [.75,-0.28], [1.,0.], 
 [1.25,0.22], [1.5,0.38], [1.75,0.47]];

draw2d(yrange=[-2,1], 
 color=blue, explicit(log(x), x,0,2), 
 color=red, point_type=filled_diamant, point_size=2, points(datalist));

reset()$kill(all)$

 Exercise 29.

load(draw)$

draw2d(nticks=29, parametric(sin(4*%pi*t),cos(4*%pi*t), t,0,4));

reset()$kill(all)$

 Exercise 30.

load(draw)$

draw3d(explicit(1/(2*%pi)*exp(-0.5*(x^2+y^2)), x,-3,3, y,-3,3));

reset()$kill(all)$

 Exercise 31.

x: [1,2,3]; y: [4,5,6];

x+y; x-y; x.y; 3*x;

reset()$kill(all)$

 Exercise 32.

A: matrix([1,2,3],[4,5,6],[7,8,9]);

B: matrix([-1,0,2],[-2,1,3],[2,4,-1]);

A+B; A-B; 3*A; A.B; A^^2; B^^(-1);

determinant(A); transpose(A);

A^^(-1);

reset()$kill(all)$

 Exercise 33.

A: matrix([1,2,3],[4,5,6],[7,8,9]);

B: matrix([-1,0,2],[-2,1,3],[2,4,-1]);

rank(A); rank(B);

nullity(A); nullity(B);

nullspace(A); nullspace(B);

columnspace(A); columnspace(B);

CS: columnspace(A); a1*first(CS)+a2*second(CS);

reset()$kill(all)$

 Exercise 34.

"(a)"

eq1: 2*x[1]+3*x[2]+4*x[3]= 2;

eq2: 4*x[1]+3*x[2]+  x[3]=10;

eq3:   x[1]+2*x[2]+4*x[3]= 5;

solve([eq1,eq2,eq3], [x[1],x[2],x[3]]);

"(b)"

eq1: 2*x[1]+2*x[2]+  x[3]+3*x[4]=10;

eq2: 3*x[1]+5*x[2]+2*x[3]-  x[4]=30;

eq3:   x[1]+2*x[2]+  x[3]-  x[4]=12;

solve([eq1,eq2,eq3], [x[1],x[2],x[3],x[4]]);

"(c)"

eq1: 2*x[1]+10*x[2]+4*x[3]+ 9*x[4]= 1;

eq2:   x[1]+ 6*x[2]+5*x[3]+ 3*x[4]= 1;

eq3: 2*x[1]+16*x[2]+9*x[3]+11*x[4]=-1;

eq4:   x[1]+ 5*x[2]+2*x[3]+ 5*x[4]= 2;

eq5:           x[2]+3*x[3]        = 4;

solve([eq1,eq2,eq3,eq4,eq5], [x[1],x[2],x[3],x[4]]);

reset()$kill(all)$

 Exercise 35.

A: matrix([1,2],[3,4]);

es: eigenvectors(A);

eigval: es[1][1];

v[1]: es[2][1];  v[2]: es[2][2];

reset()$kill(all)$

 Exercise 36.

A: matrix([1,2,1],[2,1,3],[1,3,1]);

es: eigenvectors(A);

eigvals: float(realpart(es[1][1]));

eigvects: float(realpart(es[2]));

reset()$kill(all)$

 Exercise 37.

A: diagmatrix(3,1);

esA: eigenvectors(A);

numberofeigenvaluesA:   length(esA[1][1]);

algebraicmultiplicityA: esA[1][2];

geometricmultiplicityA: length(esA[2][1]);

B: matrix([1,1,1],[0,1,1],[0,0,1]);

esB: eigenvectors(B);

numberofeigenvaluesB:   length(esB[1][1]);

algebraicmultiplicityB: esB[1][2];

geometricmultiplicityB: length(esB[2][1]);

reset()$kill(all)$

 Exercise 38.

limit((n+1)/(n-1),n,inf);

limit((1+1/n)^n,n,inf);

limit(sin(x)/x,x,0);

limit(sin(1/x)/x,x,0);

limit(sin(1/x),x,0);

limit(sin(1/x)*x,x,0);

limit(exp(1/x),x,0);

limit(exp(1/x),x,0,plus);

limit(exp(1/x),x,0,minus);

reset()$kill(all)$

 Exercise 39.

limit(((x+h)^5-x^5)/h,h,0);

reset()$kill(all)$

 Exercise 40.

sum(binomial(n,k),k,0,n), simpsum;

reset()$kill(all)$

 Exercise 41.

sum(a[i]*b[n-i+1]-a[n-i+1]*b[i],i,1,n), n:10;

reset()$kill(all)$

 Exercise 42.

product((x-y),y,1,1000);

reset()$kill(all)$

 Exercise 43.

diff(x^alpha*y^beta,x); diff(x^alpha*y^beta,y);

diff(x^alpha*y^beta,x,2); diff(x^alpha*y^beta,y,2);

diff(x^alpha*y^beta,x,1,y,1);

reset()$kill(all)$

 Exercise 44.

diff(log(f(x)));

reset()$kill(all)$

 Exercise 45.

depends(f,[x,y,t]); depends(x,y); depends(y,t);

diff(f,t);

diff(f,t,2);

derivabbrev: true$

diff(f,t);

diff(f,t,2);

reset()$kill(all)$

 Exercise 46.

jacobian([exp(-x^2-y^2), x^2+y^2],[x,y]);

reset()$kill(all)$

 Exercise 47.

powerseries(sqrt(1+x^2),x,0);

reset()$kill(all)$

 Exercise 48.

f(x):= sqrt(1+x^2);

t(x):= ''(taylor(f(x),x,0,4));

plot2d([f(x),t(x)], [x,-1.5,1.5]);

reset()$kill(all)$

 Exercise 49.

f(x):= (x^2+1)/x;

fx: diff(f(x),x);

fxx: diff(f(x),x,2);

crit: solve(fx,x);

ev(fxx, crit[1]);

ev(fxx, crit[2]);

plot2d(f(x), [x,-2,2],[y,-5,5]);

reset()$kill(all)$

 Exercise 50.

f(x,y):= -x^2+x*y+y^2;

fx: diff(f(x,y), x);

fy: diff(f(x,y), y);

crit: solve([fx,fy], [x,y]);

H: hessian(f(x,y), [x,y]);

eigenvalues(ev(H,crit[1]));

plot3d(f(x,y), [x,-1,1],[y,-1,1]);

reset()$kill(all)$

 Exercise 51.

g(x,y):= 2*(y-x^2)^2+(1-x)^2;

gx: diff(g(x,y), x);

gy: diff(g(x,y), y);

crit: solve([gx,gy], [x,y]);

H: hessian(g(x,y), [x,y]);

eigenvalues(ev(H,crit)), numer;

plot3d(g(x,y), [x,0.5,1.5],[y,0.5,1.5]);

reset()$kill(all)$

 Exercise 52.

h(x,y):= 1/x*log(x)-y^2+1;

hx: diff(h(x,y), x);

hy: diff(h(x,y), y);

crit: [solve(hx,x), solve(hy,y)];

H: hessian(h(x,y),[x,y]);

eigenvalues(ev(H,crit));

plot3d(h(x,y), [x,1,5],[y,-1,1]);

reset()$kill(all)$

 Exercise 53.

integrate(x^3*sin(-x),x);

reset()$kill(all)$

 Exercise 54.

integrate(x^3*sin(-x),x,0,%pi);

reset()$kill(all)$

 Exercise 55.

qres: quad_qags(tan(log(x)),x,1,2);

a: qres[1];

reset()$kill(all)$

 Exercise 56.

sola: ode2('diff(y,x)-k*y/x=0, y, x); ic1(sola, x=1, y=1); method;

solb: ode2(x*'diff(y,x)-(1+y)=0, y, x); ic1(solb, x=1, y=1); method;

solc: ode2('diff(y,x)=x*y, y, x); ic1(solc, x=1, y=1); method;

sold: ode2('diff(y,x)+%e^y=0, y, x); ic1(sold, x=1, y=1); method;

sole: ode2('diff(y,x)=y^2, y, x); ic1(sole, x=1, y=1); method;

solf: ode2('diff(y,x)=sqrt(x^3*y), y, x); ic1(solf, x=1, y=1); method;

reset()$kill(all)$

 Exercise 57.

sola: ode2('diff(y,x,2)+'diff(y,x)-2*y=3, y, x); method;

ic2(sola, x=0,y=1,'diff(y,x)=1);

solb: ode2('diff(y,x,2)-6*'diff(y,x)+9*y=0, y, x); method;

ic2(solb, x=0,y=2,'diff(y,x)=0);

solc: ode2('diff(y,x,2)+2*'diff(y,x)+17*y=0, y, x); method;

ic2(solc, x=0,y=0,'diff(y,x)=1);

reset()$kill(all)$

 Exercise 58.

sola: desolve(diff(y(x),x)-(1+y(x))=0, y(x));

atvalue(y(x), x=0, 1); desolve(diff(y(x),x)-(1+y(x))=0, y(x));

kill(y)$

solb: desolve(diff(y(x),x,2)+diff(y(x),x)-2*y(x)=3, y(x));

atvalue(y(x), x=0, 1); atvalue(diff(y(x), x), x=0, 1);

desolve(diff(y(x),x,2)+diff(y(x),x)-2*y(x)=3, y(x));

kill(y)$

solc: desolve(diff(y(x),x,2)-6*diff(y(x),x)+9*y(x)=3, y(x));

atvalue(y(x), x=0, 2); atvalue(diff(y(x),x), x=0, 0);

desolve(diff(y(x),x,2)-6*diff(y(x),x)+9*y(x)=3, y(x));

kill(y)$

sold: desolve(diff(y(x),x,2)+2*diff(y(x),x)+17*y(x)=3, y(x));

atvalue(y(x), x=0, 0); atvalue(diff(y(x),x), x=0, 1);

desolve(diff(y(x),x,2)+2*diff(y(x),x)+17*y(x)=3, y(x));

kill(y)$

reset()$kill(all)$

 Exercise 59.

/*a*/ plotdf(y/x);

/*b*/ plotdf((1+y)/x);

/*c*/ plotdf(y*x);

/*d*/ plotdf(-%e^y);

/*e*/ plotdf(y^2);

/*f*/ plotdf(sqrt(x^3*y),[x,0.001,10],[y,0.001,10]);

reset()$kill(all)$

 Exercise 60.

plotdf([x*(1-y),-y*(1-x)],[x,0,3],[y,0,3]);

reset()$kill(all)$