# Introduction to Maxima

## Einleitung

Computer Algebra System (CAS)

Eingabe

2+3;

4*5$

2+3; 4*5;

2+3*(4+5)
+6*7-8/4;

/* clear working space */
 reset()$ kill(all)$

Taschenrechner

5+3;

22-7;

121/11;

25*4;

2^8;

(2+3)^4-(5+6+7)/(2+4);

2^100;

sqrt(4);

% * 6;

%o5 * 6;

/* clear working space */
 reset()$ kill(all)$

Zahlen

11/3;

33/9;

sqrt(2);

sqrt(12);

sin(%pi);

log(%e^2);

atan(1);

33.0/9.0;

sqrt(2.0);

float(33/9);

33/9, numer;

/* clear working space */
 reset()$ kill(all)$

Gleitkommazahlen

2/10 * 11 - 2 - 4/20;

2.0/10.0 * 11.0 - 2.0 - 4.0/20.0;

float(%pi);

fpprec: 500$

bfloat(%pi);

set_display(ascii)$

bfloat(%pi);

100!;

set_display(xml)$

/* clear working space */
 reset()$ kill(all)$

Variable und Funktionen

x;

x: 2+3;

x;

y: 2*x^2;

sqr(x):= x^2;

sqr(4);

sindeg(x):= sin(x*%pi/180);

sindeg(45);

norm(x,y):= sqrt(x^2+y^2);

norm(3,4);

/* clear working space */
 reset()$ kill(all)$

Gleichungen

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

float(%);

solve(x^2+3*x-1, x);

eq1: 3*x^2-y^2=2;

eq2: x^2+y^2=2;

solve([eq1,eq2], [x,y]);

/* clear working space */
 reset()$ kill(all)$

Algebraische Ausdruecke

solve(a*x^2+b*x+c=0, x);

(x+y)*(x-y);

expand(%);

factor(%);

(x^2-y^2)/(x+y)^2;

ratsimp(%);

(%e^x-1)/(1+%e^(x/2));

radcan(%);

/* clear working space */
 reset()$ kill(all)$

Hilfe

? sqrt

?? sqrt

apropos("sqrt");

?sqrt

/* clear working space */
 reset()$ kill(all)$

## Matrixalgebra

Matrizenrechnung

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

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

C: matrix([1,2,3],[4,5,6]);

A+B;

5*A;

A.B;

A^^2;

A.C;

C.A;

A+C;

/* clear working space */
 reset()$ kill(all)$

Matrizenrechnung -- Achtung!

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

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

A*B;

A^2;

/* clear working space */
 reset()$ kill(all)$

Matrixoperationen

ident(3);

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

transpose(A);

invert(A);

A^^(-1);

/* clear working space */
 reset()$ kill(all)$

Matrixelemente

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

A[2];

A[2,1];

A[2,1]: 10;

A;

/* clear working space */
 reset()$ kill(all)$

Vektoren

x: [1,2,3,4];

x[3];

y[3];

kill(x);

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

x: [1,2];

A.x;

x.A;

/* clear working space */
 reset()$ kill(all)$

Skalarprodukt

x: [1,2,3];

y: [2,4,6];

x.y;

sqrt(x.x);

/* clear working space */
 reset()$ kill(all)$

Lineares Gleichungssystem -- I

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

b: [-1,-15,2];

A^^(-1).b;

echelon(A)

/* clear working space */
 reset()$ kill(all)$

Lineares Gleichungssystem -- II

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

eq2: 3*x[1]+3*x[2]+8*x[3]=-15;

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

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

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

%, %r1=2;

/* clear working space */
 reset()$ kill(all)$

## Vektorraum

Rang, Bild und Kern

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

rank(A);

NS: nullspace(A);

CS: columnspace(A);

first(CS);

second(CS);

/* clear working space */
 reset()$ kill(all)$

## Determinante

Determinante

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

determinant(A);

B: adjoint(A);

A.B;

/* clear working space */
 reset()$ kill(all)$

## Eigenwerte

Eigenwerte

A: matrix([1,0],[6,6]);

charpoly(A,x);

eigenvalues(A);

eigvals:eigenvalues(A)[1];

multiplicities:eigenvalues(A)[2];

es: eigenvectors(A);

eigvals: es[1][1];

multiplicities: es[1][2];

vectors: es[2];

/* clear working space */
 reset()$ kill(all)$

Eigenwerte -- numerisch

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

es: eigenvectors(A);

eigvals: rectform(es[1][1]);

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

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

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

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

/* clear working space */
 reset()$ kill(all)$

Hauptminoren

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

H1: A[1][1];

H2: determinant(submatrix(3,A,3));

H3: determinant(A);

/* clear working space */
 reset()$ kill(all)$

Allgemeine Hauptminoren

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

aH1: A[1][1];

aH2: A[2][2];

aH3: A[3][3];

aH12: determinant(submatrix(3,A,3));

aH13: determinant(submatrix(2,A,2));

aH23: determinant(submatrix(1,A,1));

aH123: determinant(A);

/* clear working space */
 reset()$ kill(all)$

## Funktionen

Graph einer univariaten Funktion

plot2d(x-log(x), [x,0,5]);

f(x):= x-log(x);

plot2d(f(x), [x,0,5]);

plot2d(f(x), [x,0.01,5]);

plot2d(f(x), [x,0.01,5], [y,0,4]);

plot2d(sin(1/x), [x,0,0.1]);

wxplot2d(f(x), [x,0,5]);

load(draw)$

draw2d(explicit(f(x), x,0,5), yrange=[0,4]);

/* clear working space */
 reset()$ kill(all)$

Graph einer univariaten Funktion II

load(draw)$

draw2d( explicit(1, x,-2,0),
explicit(1-x^2/2, x,0,1),
explicit(x, x,1,3));

/* clear working space */
 reset()$ kill(all)$

Inverse Funktion

eq: y=2*x-1;

solve(eq, x);

eq: y=x^3;

solve(eq, x);

/* clear working space */
 reset()$ kill(all)$

Grenzwerte von Folgen

limit(2+3*n^2, n, inf);

limit(2^(-n)*n^(-1), n, inf);

limit((1+1/n)/(2-3/n^2), n, inf);

limit(sin(n)/n^2, n, inf);

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

/* clear working space */
 reset()$ kill(all)$

Grenzwerte von Funktionen

limit((x^2-1)/abs(x-1), x, 1, plus);

limit((x^2-1)/abs(x-1), x, 1, minus);

limit((x^2-1)/abs(x-1), x, 1);

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

/* clear working space */
 reset()$ kill(all)$

Graph einer bivariaten Funktion

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

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

load(draw)$

draw3d(explicit(f(x,y), x,-2,2, y,-2,2));

draw3d(enhanced3d=true, explicit(f(x,y), x,-2,2, y,-2,2));

/* clear working space */
 reset()$ kill(all)$

Niveaulinien einer bivariaten Funktion

load(draw)$

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

draw3d(explicit(f(x,y), x,-2,2, y,-2,2),
contour=map,contour_levels=12);

draw3d(explicit(f(x,y), x,-2,2, y,-2,2),
contour=base,contour_levels=12);

draw3d(explicit(f(x,y), x,-2,2, y,-2,2),
contour=surface,contour_levels=12);

/* clear working space */
 reset()$ kill(all)$

Wege

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

load(draw)$

draw2d(color=blue, nticks=1000, parametric(t*sin(2*%pi*t),t*cos(2*%pi*t), t,0,2));

/* clear working space */
 reset()$ kill(all)$

## Differentialrechnung

Ableitung und Differential

diff(x^a,x);

diff(x^a,x,2);

diff(x^a);

%,del(a):0;

declare(a,constant);

diff(x^a);

/* clear working space */
 reset()$ kill(all)$

Lokale Monotonie

f(x):=2*x^3-12*x^2+18*x-1;

df(x):=''(diff(f(x),x));

z: solve(df(x)=0,x);

df([0,2,4]);

/* clear working space */
 reset()$ kill(all)$

Lokale Konkavität

f(x):=2*x^3-12*x^2+18*x-1;

d2f(x):=''(diff(f(x),x,2));

z: solve(d2f(x)=0,x);

d2f([1,3]);

/* clear working space */
 reset()$ kill(all)$

Elastizität

depends(u,f); depends(f,x); depends(x,v);

u(f):=log(f); x(v):=exp(v);

diff(u,v);

%,'diff(u,f):diff(u(f),f),
'diff(x,v):diff(x(v),v), exp(v):x;

derivabbrev:true$

%o4;

/* clear working space */
 reset()$ kill(all)$

Partielle Ableitung

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

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

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

diff(f(x,y),x,2);

diff(f(x,y),y,2);

diff(f(x,y),x,1,y,1);

diff(f(x,y),y,1,x,1);

/* clear working space */
 reset()$ kill(all)$

Gradient und Richtungsableitung

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

Df: [''(diff(f(x,y),x)), ''(diff(f(x,y),y))];

Dfx:Df,x:3,y:2;

h: [1,-2];

Dfx.h/sqrt(h.h);

/* clear working space */
 reset()$ kill(all)$

Totales Differential

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

diff(f(x,y));

/* clear working space */
 reset()$ kill(all)$

Jacobische Matrix

f(x,y):= [exp(-x^2-y^2)];

jacobian(f(x,y),[x,y]);

f(x):= [exp(-x[1]^2-x[2]^2)];

jacobian(f(x),[x[1],x[2]]);

f(x):= [x[1]^2+x[2]^2, x[1]^2-x[2]^2];

jacobian(f(x),[x[1],x[2]]);

s(t):= [cos(t), sin(t)];

jacobian(s(t),[t]);

/* clear working space */
 reset()$ kill(all)$

## Inverse und implizite Funktionen

Graph einer impliziten Funktion

load(implicit_plot)$

implicit_plot(x^2-y^3+3*y-1=0, [x,-4,4], [y,-4,4]);

load(draw)$

draw2d(implicit(x^2-y^3+3*y-1=0, x,-4,4, y,-4,4));

draw3d(enhanced3d=true, implicit(x^2+sin(y)=z^2, x,-2,2, y,-2,2, z,-2,2));

/* clear working space */
 reset()$ kill(all)$

## Taylorreihen

Taylorreihe

taylor(exp(x),x,0,3);

plot2d([exp(x),%], [x,-3,3]);

T(x):= ''(taylor(exp(x),x,0,3));

plot2d([exp(x),T(x)], [x,-3,3]);

powerseries(exp(x),x,0);

niceindices(%);

/* clear working space */
 reset()$ kill(all)$

Taylorreihe II

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

taylor(f(x,y),[x,y],[0,0],[2,2]);

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

%, x:0, y:0;

/* clear working space */
 reset()$ kill(all)$

## Integration

Unbestimmtes Integral

integrate(4+x^3-x^2+3+x-5, x);

integrate(x*exp(x), x);

integrate(x^2*cos(x), x);

integrate(2*x*exp(x^2), x);

/* clear working space */
 reset()$ kill(all)$

Bestimmtes Integral

integrate(1/(x*log(x)), x, %e, 10);

float(%);

/* clear working space */
 reset()$ kill(all)$

Bestimmtes Integral

integrate(1/sqrt(x), x,0,1);

integrate(1/x^2, x,1,inf);

integrate(1/x, x,1,inf);

integrate(x*exp(-x^2/2), x,minf,inf);

integrate(x/(1+x^2), x,minf,inf);

/* clear working space */
 reset()$ kill(all)$

Doppelintegral

integrate( integrate(1-x-y^2+x*y^2, x,0,1), y,-1,1);

/* clear working space */
 reset()$ kill(all)$

## Extrema

Globale Extrema I

f(x):= exp(x)-2*x;

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

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

x0: solve(fx=0,x);

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

is(fxx>0);

/* clear working space */
 reset()$ kill(all)$

Globale Extrema II

f(x,y):= 4*x^(1/4)*y^(1/4)-x-y;

plot3d(f(x,y), [x,0,2], [y,0,2]);

load(draw)$

draw3d(explicit(f(x,y), x,0,2, y,0,2),
surface_hide=true);

draw3d(explicit(f(x,y), x,0,2, y,0,2),
zrange=[0,2], contour=map, contour_levels=20);

Globale Extrema II (Forts.)

[fx,fy]: [diff(f(x,y),x), diff(f(x,y),y)];

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

assume(x>0,y>0);

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

solve(fx=0,x);

xi: x,%[3];

eqy: fy=0, x=xi;

solve(eqy,y)

y0: y, %[1];

x0: xi, y=y0;

crit: [x0,y0];

Globale Extrema II (Forts.)

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

assume(x>0,y>0);

H1: H[1,1];

H2: determinant(H);

is(H1<0);

is(H2>0);

is(H1<0 and H2>0);

ev: eigenvalues(H)[1];

is(ev[1]<0);

is(ev[2]<0);

/* clear working space */
 reset()$ kill(all)$

Lokale Extrema I

f(x):= x^3/12-x^2+3*x+1;

plot2d(f(x), [x,0,8]);

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

crit: solve(fx=0,x);

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

fxx, crit[1];

fxx, crit[2];

/* clear working space */
 reset()$ kill(all)$

Lokale Extrema II

f(x,y):= x^3/6-x+x*y^2/4;

plot3d(f(x,y), [x,-2,2], [y,-3,3]);

load(draw)$

draw3d(explicit(f(x,y), x,-2,2, y,-3,3),
contour=map, contour_levels=20);

[fx,fy]: [diff(f(x,y),x), diff(f(x,y),y)];

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

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

H1: H, crit[1];

is(H1[1,1]<0 and determinant(H1)>0);

H3: H, crit[3];

is(determinant(H3)<0);

/* clear working space */
 reset()$ kill(all)$

## Lagrange-Funktion

## Kuhn-Tucker Bedingung

## Differentialgleichungen

ODE Vektorfeld

plotdf(1.5*y*(2-y), [x,0,2.5], [y,0,3])$

/* clear working space */
 reset()$ kill(all)$

ODE I

dg: 'diff(y,t)+t*y^2=0;

ode2(dg,y,t);

solve(%,y);

ic1(%, t=0, y=1);

y(t):=''(ev(y,%));

plot2d(y(t), [t,0,3]);

/* clear working space */
 reset()$ kill(all)$

ODE linear homogen

dg: 'diff(y,t)+3*t^2*y=0;

ode2(dg,y,t);

y(t):=''(ev(y,%));

/* clear working space */
 reset()$ kill(all)$

ODE linear inhomogen

dg: 'diff(y,t)-3*y=6;

ode2(dg,y,t);

ic1(%, t=0, y=1);

y(t):=''(ev(y,%));

plot2d(y(t), [t,0,1]);

/* clear working space */
 reset()$ kill(all)$

ODE Marktdynamik

dg: 'diff(p,t)+j*(b-d)*p=j*(a+g);

ode2(dg,p,t);

ic1(%, t=0, p=p0);

p(t):=''(ev(p,%));

/* clear working space */
 reset()$ kill(all)$

ODE II

dg: 'diff(y,t,2)-'diff(y,t)-2*y=0;

ode2(dg,y,t);

dg: 'diff(y,t,2)+'diff(y,t)-2*y=-10;

ode2(dg,y,t);

dg: 'diff(y,t,2)+4*'diff(y,t)+4*y=0;

ode2(dg,y,t);

dg: 'diff(y,t,2)+'diff(y,t)+y=0;

ode2(dg,y,t);

/* clear working space */
 reset()$ kill(all)$

ODE II

dg: 'diff(y,t,2)+'diff(y,t)-2*y=-10;

ode2(dg,y,t);

ic2(%, t=0, y=12, 'diff(y,t)=-2);

y(t):=''(ev(y,%));

plot2d(y(t), [t,0,1]);

/* clear working space */
 reset()$ kill(all)$

## Kontrolltheorie