Zurück zum Inhaltsverzeichnis

Kapitel 23

Minima und Maxima von Funktionen

Funktionen einer Variablen

Polynome

In der Regel wird man sich die Funktion zuerst zeichnen.

> restart:

> f:=x^4-x^2;

f := x^4-x^2

> plot(f,x);

[Maple Plot]

Nur weiß man den günstigen Bereich nicht immer von vornherein. Also kann man es mit dem Befehl extrema versuchen.

> extrema(f,{},x,'s');s;

{0, -1/4}

{{x = 0}, {x = 1/2*sqrt(2)}, {x = -1/2*sqrt(2)}}

Dieser Befehl ist eigentlich für die Bestimmung von Extrema multivariabler Funktionen (mit Nebendedingungen) gedacht (s.u.), kann aber auch hier bedingt eingesetzt werden. Dazu ordnet man zunächst die möglichen Extremstellen (sort(..,`<`) funktioniert nur für type numeric, wozu Wurzeln nicht gehören):

> kand:=sort([seq(eval(x,gl),gl=s)],(x,y)->is(x<y));

kand := [-1/2*sqrt(2), 0, 1/2*sqrt(2)]

Oder etwas umständlicher:

> #x1:=min(seq(evalf(op(s[i,1])[2]),i=1..nops(s)));

> #x2:=max(seq(evalf(op(s[i,1])[2]),i=1..nops(s)));

Nun können wir eine Zeichnung mit angepaßtem Plotbereich erstellen.

> plot(f,x=kand[1]-1..kand[-1]+1);

[Maple Plot]

>

Der Befehl extrema liefert nur die Kandidaten für Extrema, untersucht also nur die notwendige Bedingung:

> f:=x^3;

f := x^3

> extrema(f,{},x,'s');s;

{0}

{{x = 0}}

Und wenn kein Extremum existiert, liefert extrema ein komplexes Ergebnis:

> f:=x^3+x+1;

f := x^3+x+1

> extrema(f,{},x,'s');s;

{min(-2/9*I*sqrt(3)+1,2/9*I*sqrt(3)+1), max(-2/9*I*...

{{x = 1/3*I*sqrt(3)}, {x = -1/3*I*sqrt(3)}}

>

Trotzdem kann man auf diese Art bequem eine 'Minikurvendiskussion' schreiben.

> restart:

> kd:=proc(f)
global stellen:
extrema(f,{},x,'s');
stellen:=sort([seq(evalf(Re(op(s[i,1])[2])),i=1..nops(s))]);
print(seq([stellen[i],subs(x=stellen[i],f)],i=1..nops(s)));
plot(f,x=stellen[1]-1..stellen[-1]+1);
end;

kd := proc (f) global stellen; extrema(f,{},x,'s');...
kd := proc (f) global stellen; extrema(f,{},x,'s');...
kd := proc (f) global stellen; extrema(f,{},x,'s');...
kd := proc (f) global stellen; extrema(f,{},x,'s');...
kd := proc (f) global stellen; extrema(f,{},x,'s');...
kd := proc (f) global stellen; extrema(f,{},x,'s');...
kd := proc (f) global stellen; extrema(f,{},x,'s');...

>

> kd(x^4-3*x^2+x);

[-1.300839566, -3.513905038], [.1699384435, .841352...

[Maple Plot]

>

Aber wie gesagt - man muß mitdenken:

> kd(x^3+x+2);

[0., 2.], [0., 2.]

[Maple Plot]

>

Wenn wirklich Extrema vorliegen

> f:=x^4/2-4*x^2;

f := 1/2*x^4-4*x^2

> kd(f);

[-2., -8.000000000], [0., 0.], [2., -8.000000000]

[Maple Plot]

kann man sie auch mit minimize und maximize finden.

> minimize(f,x,location);

-8, {[{x = -2}, -8], [{x = 2}, -8]}

> maximize(f,x=-1..1,location);

0, {[{x = 0}, 0]}

> maximize(f,x,location);

infinity, {[{x = -infinity}, infinity], [{x = infin...

>

> f:=int((x+2)*x*(x-1),x)+1;

f := 1/4*x^4+1/3*x^3-x^2+1

> kd(f);

[-2., -1.666666667], [0., 1.], [1., .5833333333]

[Maple Plot]

> minimize(f,location);

-5/3, {[{x = -2}, -5/3]}

>

Aber hier streikt minimize:

> g:=x^4-3*x^2+x;

g := x^4-3*x^2+x

> kd(g);

[-1.300839566, -3.513905038], [.1699384435, .841352...

[Maple Plot]

> minimize(g,x,location);

minimize(x^4-3*x^2+x,x,location,location = false), ...

Das liegt daran, daß Maple bei der Lösung von kubischen Gleichungen und Gleichungen vierten Grades 'durch das Komplexe geht' (wenn es erforderlich ist):

> solve(diff(g,x));

1/2*(-1+I*sqrt(7))^(1/3)+1/((-1+I*sqrt(7))^(1/3)), ...
1/2*(-1+I*sqrt(7))^(1/3)+1/((-1+I*sqrt(7))^(1/3)), ...
1/2*(-1+I*sqrt(7))^(1/3)+1/((-1+I*sqrt(7))^(1/3)), ...

> evalc([%]);

[sqrt(2)*cos(-1/3*arctan(sqrt(7))+1/3*Pi), -1/2*sqr...
[sqrt(2)*cos(-1/3*arctan(sqrt(7))+1/3*Pi), -1/2*sqr...

>

Dann rechnet minimize nicht weiter. Das kann aber so umgangen werden:

> _EnvExplicit:=false;

_EnvExplicit := false

> minimize(g,x,location);

RootOf(4*_Z^3-6*_Z+1,index = 3)^4-3*RootOf(4*_Z^3-6...
RootOf(4*_Z^3-6*_Z+1,index = 3)^4-3*RootOf(4*_Z^3-6...
RootOf(4*_Z^3-6*_Z+1,index = 3)^4-3*RootOf(4*_Z^3-6...
RootOf(4*_Z^3-6*_Z+1,index = 3)^4-3*RootOf(4*_Z^3-6...

> evalf(%);

-3.513905038, {[{x = -1.300839566}, -3.513905038]}

>

Für Polynome vom Grad > 5 (also Grad der Ableitung > 4) ist dies nicht erforderlich, weil dann immer die RootOf-Darstellung genommen werden muß.

> _EnvExplicit:=true;

_EnvExplicit := true

> h:=convert(series(sin(x),x,8),polynom);

h := x-1/6*x^3+1/120*x^5-1/5040*x^7

> kd(h);

[-3.928084044, 1.243304074], [-3.928084044, 1.24330...
[-3.928084044, 1.243304074], [-3.928084044, 1.24330...

[Maple Plot]

> evalf(minimize(h,x=-4..0,location));

-.9998435003, {[{x = -1.569905825}, -.9998435003]}

Minimize gibt übrigens das absolute Minimum zurück (dgl. für maximize):

> evalf(minimize(h,x=-4..4,location));

-1.384126984, {[{x = 4.}, -1.384126984]}

>

Gebrochenrationalen Funktionen

Bei gebrochenrationalen Funktionen lässt sich minimize auch so einsetzten:

> f:=(x^4+x+7)/(x^6-4);

f := (x^4+x+7)/(x^6-4)

>

> plot(f,x=-5..5,-10..10);

[Maple Plot]

Bestimmung der Pole

> minimize(f,location);

-infinity, {[{x = RootOf(_Z^3+2,-1.259921050)}, -in...

> -1.259921050^3;

-2.000000000

> evalf(%);

-2.000000000

> evalf(maximize(f,x,location));

Float(infinity), {[{x = 1.259921050}, Float(infinit...

Relatives Maximum:

> maximize(f,x=-1..1,location);

(RootOf(2*_Z^9+16*_Z^3+5*_Z^6+4+42*_Z^5,index = 5)^...
(RootOf(2*_Z^9+16*_Z^3+5*_Z^6+4+42*_Z^5,index = 5)^...
(RootOf(2*_Z^9+16*_Z^3+5*_Z^6+4+42*_Z^5,index = 5)^...
(RootOf(2*_Z^9+16*_Z^3+5*_Z^6+4+42*_Z^5,index = 5)^...
(RootOf(2*_Z^9+16*_Z^3+5*_Z^6+4+42*_Z^5,index = 5)^...
(RootOf(2*_Z^9+16*_Z^3+5*_Z^6+4+42*_Z^5,index = 5)^...
(RootOf(2*_Z^9+16*_Z^3+5*_Z^6+4+42*_Z^5,index = 5)^...

> evalf(%);

-1.646347486, {[{x = -.5288119415}, -1.646347486]}

Und die Asymptote

> minimize(f,x=2..infinity,location);

0, {[{x = infinity}, 0]}

>

Trigonometrische Funktionen

> minimize(sin(x),location);

-1, {[{x = -1/2*Pi+2*Pi*_Z0}, -1]}

> minimize(tan(x),location);

-infinity, {[{x = 1/2*Pi+Pi*_Z1}, -infinity]}

Exponential- und Logarithmusfunktionen

> minimize(exp(x),location);

0, {[{x = -infinity}, 0]}

> minimize(exp(-(x+4)^2),location);

0, {[{x = infinity}, 0], [{x = -infinity}, 0]}

> maximize(exp(-(x+4)^2),location);

1, {[x = -4, 1]}

> minimize(ln(x),x,location);

-infinity, {[{x = 0}, -infinity]}

> minimize(1/ln(x),x=1..infinity,location);

0, {[{x = infinity}, 0]}

> maximize(1/ln(x),x=1..infinity,location);

infinity, {[{}, infinity]}

Hier gibt es Probleme

> minimize(1/ln(x),x,location);

Error, (in kernels) too many levels of recursion

> minimize(ln(x)^2);

Error, (in minimize/cell/power/univariate) complex argument to max/min

> assume(x>1):minimize(ln(x)^2);

Error, (in minimize/cell/power/univariate) complex argument to max/min

Aber

> x:='x':minimize(ln(x)^2,x=0..infinity,location);

0, {[{x = 1}, 0]}

>

>

Transzendente Funktionen (allgemeiner Fall)

> minimize(sin(x)+x,x=1..4,location);

sin(1)+1, {[{x = 1}, sin(1)+1]}

> minimize(sin(x)+2*x,x=0..4,location);

minimize(sin(x)+2*x,x = 0 .. 4,location,location = ...

> minimize(sin(x)+2*x,x,location);

minimize(sin(x)+2*x,x,location,location = false), {...

Übrigens:

> extrema(sin(x)+2*x,{},x,'s');s;

{I*sqrt(3)+2*Pi-2*arccos(2)}

{{x = Pi-arccos(2)}}

> x:='x':

> diff(sin(x)+2*x,x);

cos(x)+2

> solve(%);

Pi-arccos(2)

> evalf(arccos(2));

1.316957897*I

> cos(%);

2.000000000

> minimize(x*sin(x),x);

minimize(x*sin(x),x)

Aber

> minimize(x*sin(x),x=1..12);

RootOf(tan(_Z)+_Z,11.08553841)*sin(RootOf(tan(_Z)+_...

> minimize(x*sin(x),x=1..10);

10*sin(10)

> diff(x*sin(x),x);

sin(x)+x*cos(x)

> solve(%);

RootOf(tan(_Z)+_Z)

> allvalues(%);

RootOf(tan(_Z)+_Z,0.)

>

> minimize(exp(x)+x);

-infinity

> minimize(exp(x)*x,location);

-exp(-1), {[{x = -1}, -exp(-1)]}

> maximize(x*exp(-(x-1)^2),location);

(1/2+1/2*sqrt(3))*exp(-(-1/2+1/2*sqrt(3))^2), {[{x ...

>

Noch ein Beispiel

> f:=x^2+sin(x)+cos(2*x);

f := x^2+sin(x)+cos(2*x)

> minimize(f,x);

minimize(x^2+sin(x)+cos(2*x),x)

Das Minimum kann nicht gefunden werden, weil die transzendente Gleichung nicht gelöst werden kann

> solve(diff(f,x));

> _SolutionsMayBeLost;

true

> _SolutionsMayBeLost:='_SolutionsMayBeLost':

> fsolve(diff(f,x));

-1.074907239

> _SolutionsMayBeLost;

_SolutionsMayBeLost

>

Funktionen von mehreren Variablen (Untersuchung mit minimize und maximize)

> minimize(x*y,location);

-infinity, {[{y = -infinity, x = infinity}, -infini...

> minimize(x*y,x=1..10,y=1..10,location);

1, {[{x = 1, y = 1}, 1]}

> minimize(x^4-x^2+y^4-y^2,location);

-1/2, {[{y = 1/2*sqrt(2), x = 1/2*sqrt(2)}, -1/2], ...
-1/2, {[{y = 1/2*sqrt(2), x = 1/2*sqrt(2)}, -1/2], ...

> #plot3d(x^4+y^4-x^2-y^2,x=-2..2,y=-2..2);

>

> minimize(sin(x)*cos(y),location);

-1, {[{y = Pi+2*Pi*_Z46, x = 1/2*Pi+2*Pi*_Z49}, -1]...

> minimize(sin(x)*cos(y),x=0..50,y=0..4,location);

-1, {[{y = 0, x = 3/2*Pi}, -1], [{x = 5/2*Pi, y = P...
-1, {[{y = 0, x = 3/2*Pi}, -1], [{x = 5/2*Pi, y = P...
-1, {[{y = 0, x = 3/2*Pi}, -1], [{x = 5/2*Pi, y = P...
-1, {[{y = 0, x = 3/2*Pi}, -1], [{x = 5/2*Pi, y = P...

>

Hier gibt es wieder Probleme

> minimize(sin(x*y),x=0..3,y=0..3,location);

Error, (in minimize/cell/addpoint) wrong number (or type) of parameters in function union

> minimize(sin(x*y),x);

Error, (in unknown) too many levels of recursion

Achtung: das erzeugt einen Endlosausdruck, aber kein Ergebnis! (Mit Stop abbrechen und printlevel wieder auf 1 setzen)

> printlevel:=200:

> minimize(sin(x*y));

Warning, computation interrupted

> printlevel:=1:

>

Extrema multivariabler Funktionen (mit Lagrangemultiplikatoren)

Extrema von Funktionen mehrer Veränderlicher mit Nebenbedingungen

> restart:with(plots):

Warning, the name changecoords has been redefined

Üblicher Lösungsweg bei zwei Variablen und einer Nebenbedingung

> Z:=x*y; N:=x^2/3-y=25;

Z := x*y

N := 1/3*x^2-y = 25

> #Z:=x^2*y/10; N:=x^2/3-y=25;

> yx:=solve(N,y);

yx := 1/3*x^2-25

> zx:=subs(y=yx,Z);

zx := x*(1/3*x^2-25)

> simplify(diff(zx,x));

x^2-25

> solve(diff(zx,x));

5, -5

>

Lösung mit dem Befehl extrema

> extr:=extrema(Z,{N},{x,y},'L');L;

extr := {-250/3, 250/3}

{{x = 5, y = -50/3}, {x = -5, y = -50/3}}

> #allvalues(L); # für RootOfs

Veranschaulichung der Zielfunktion

> zf:=plot3d(Z,x=-10..10,y=-30..20,color=grey):zf;

Die Nebenbedingung als Fläche

> nbimpl:=implicitplot3d( N ,x=-10..10,y=-30..20,
zz=-200..200,style=patchnogrid,color=yellow,grid=[20,20,5]):#nbimpl;

> display(zf,nbimpl);

Die Nebenbedingung als Raumkurve

> nb:=spacecurve([x,yx,zx],x=-10..10,color=black, thickness=2,axes=normal):display(nb,orientation=[-40,60]);

[Maple Plot]

Zwei Projektionen

> display(nb,orientation=[0,90]);

[Maple Plot]

> display(nb,orientation=[-90,90]);

[Maple Plot]

Vgl. üblicher Lösungsweg

> plot(zx,x=-10..10);

[Maple Plot]

>

> #display(zf,nb);

> display([zf,nb,nbimpl],axes=boxed);

>

Lösungspunkte

> punkt1:=pointplot3d([subs(op(L[1]),x),subs(op(L[1]),y),subs(op(L[1]),Z)],symbol=cross,symbolsize=50,color=red):

> punkt2:=pointplot3d([subs(op(L[2]),x),subs(op(L[2]),y),subs(op(L[2]),Z)],symbol=cross,symbolsize=50,color=red):

> #display(punkt2,punkt1,axes=boxed);

> display([zf,nb,nbimpl,punkt1,punkt2],axes=boxed);

[Maple Plot]

>

Veranschaulichung der Methode der Lagrangemultiplikatoren

> Z,N;

x*y, 1/3*x^2-y = 25

> Nl:=lhs(N)-25;

Nl := 1/3*x^2-y-25

> sys:={Nl,diff(Z+lambda*Nl,x),diff(Z+lambda*Nl,y)};

sys := {x-lambda, y+2/3*lambda*x, 1/3*x^2-y-25}

>

> solve(sys);

{x = 5, y = -50/3, lambda = 5}, {x = -5, y = -50/3,...

> la:=plot3d(Z+5*Nl,x=-10..10,y=-30..20,axes=boxed,style=patchcontour,contours=30,color=grey):

> display(la,punkt1,punkt2,nbimpl,nb);

[Maple Plot]

Oder als Animation

> ll:=seq(display([plot3d(Z+lambda*Nl/4,x=-10..10,y=-30..20,axes=boxed,style=patchcontour,contours=30,color=grey),punkt1,punkt2,nb]),lambda=-30..20):

> display(ll,insequence=true);

>

>

Weitere Beispiele

Maximales Volumen eines Quaders zu gegebener Oberfläche A

> Z:=x*y*z;

Z := x*y*z

> N:=2*(x*y+y*z+x*z)-A;

N := 2*x*y+2*y*z+2*x*z-A

> los:=extrema(Z,{N},{x,y,z},'s');

los := {1/6*RootOf(6*_Z^2-A)*A}

> s;

{{y = RootOf(6*_Z^2-A), x = RootOf(6*_Z^2-A), z = R...

> A:=6;

A := 6

> los;

{RootOf(_Z^2-1)}

> s;

{{y = RootOf(_Z^2-1), x = RootOf(_Z^2-1), z = RootO...

Sollte der Einheitswürfel sein :-))

Kontrolle

> A:='A':

> sys:=seq(diff(Z+lambda*N,k),k=[x,y,z]),N;

sys := y*z+lambda*(2*y+2*z), x*z+lambda*(2*x+2*z), ...

> sol:=solve({sys},{x,y,z,lambda});

sol := {y = RootOf(6*_Z^2-A), x = RootOf(6*_Z^2-A),...

> assign(sol);

> Z;

RootOf(6*_Z^2-A)^3

>

Kürzester Abstand des Punktes (x0|y0|z0) von der Ebene a*x+b*y+c*z+d=0

> restart:

> Z:=(x-x0)^2+(y-y0)^2+(z-z0)^2;

Z := (x-x0)^2+(y-y0)^2+(z-z0)^2

> N:=a*x+b*y+c*z+d;

N := a*x+b*y+c*z+d

> lot:=extrema(Z,{N},{x,y,z},'s');

lot := {(d+c*z0+b*y0+a*x0)^2/(c^2+b^2+a^2)}

> s;

{{y = -(-y0*c^2-y0*a^2+b*d+b*c*z0+b*a*x0)/(c^2+b^2+...
{{y = -(-y0*c^2-y0*a^2+b*d+b*c*z0+b*a*x0)/(c^2+b^2+...

> a,b,c,d:=3,4,5,6;

a, b, c, d := 3, 4, 5, 6

> x0,y0,z0:=1,2,3;

x0, y0, z0 := 1, 2, 3

> sqrt(op(lot));

16/5*sqrt(2)

> s;

{{y = -14/25, x = -23/25, z = -1/5}}

>

Extremale Abstände Punkt - Kugel

> restart:

> Z:=(x-x0)^2+(y-y0)^2+(z-z0)^2;

Z := (x-x0)^2+(y-y0)^2+(z-z0)^2

> N:=(x-xk)^2+(y-yk)^2+(z-zk)^2-rq;

N := (x-xk)^2+(y-yk)^2+(z-zk)^2-rq

> lote:=extrema(Z,{N},{x,y,z},'s');

lote := {RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk^2...
lote := {RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk^2...
lote := {RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk^2...

> s;

{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...
{{y = (-y0+RootOf(2*zk*z0-z0^2+2*yk*y0-y0^2-yk^2-zk...

>

> xk,yk,zk:=0,0,0;

xk, yk, zk := 0, 0, 0

> rq:=1;

rq := 1

> x0,y0,z0:=0,1,2;

x0, y0, z0 := 0, 1, 2

> lote;

{5*RootOf(-4-2*_Z+_Z^2)^2/((-1+RootOf(-4-2*_Z+_Z^2)...

> evalf(lote);

{1.527864044}

> s;

{{y = -1/(-1+RootOf(-4-2*_Z+_Z^2)), z = -2*1/(-1+Ro...

> evalf(s);

{{z = .8944271912, x = 0., y = .4472135956}}

> allvalues(sqrt(op(lote)));

sqrt((sqrt(5)+1)^2), sqrt((1-sqrt(5))^2)

> allvalues(s);

{{x = 0, y = -1/5*sqrt(5), z = -2/5*sqrt(5)}}, {{x ...

>

Extremale Abstände von Schnittkreis Kugel - Ebene zu geg. Punkt

> restart:with(plottools):with(plots):

Warning, the name changecoords has been redefined

Zielfunktion und Nebenbedingungen

> Z:=(x-x0)^2+(y-y0)^2+(z-z0)^2;

Z := (x-x0)^2+(y-y0)^2+(z-z0)^2

> N1:=(x-xk)^2+(y-yk)^2+(z-zk)^2-rq;

N1 := (x-xk)^2+(y-yk)^2+(z-zk)^2-rq

> N2:=a*x+b*y+c*z+d;

N2 := a*x+b*y+c*z+d

Allgemeine Formel

> lote:=extrema(Z,{N1,N2},{x,y,z},'s'): # man kann sich das auch ausgeben lassen...

Daten

> xk,yk,zk:=0,0,0;

> rq:=9;

> x0,y0,z0:=0,1,5;

x0,y0,z0:=-1,1,-2;

> a,b,c,d:=1/2,-1,1,-1/2;

xk, yk, zk := 0, 0, 0

rq := 9

x0, y0, z0 := 0, 1, 5

a, b, c, d := 1/2, -1, 1, -1/2

> lote;

{4/9*(-49/2*RootOf(-9-16*_Z+8*_Z^2)+219/4*RootOf(-9...

> s;

{{y = 4/9*(-23/4-1/2*RootOf(-9-16*_Z+8*_Z^2))/(-1+R...
{{y = 4/9*(-23/4-1/2*RootOf(-9-16*_Z+8*_Z^2))/(-1+R...

> allvalues(op(s));

{y = 8/153*(-25/4-1/8*sqrt(34))*sqrt(34), z = 8/153...
{y = 8/153*(-25/4-1/8*sqrt(34))*sqrt(34), z = 8/153...

Punkte

> sf:=evalf(allvalues(op(s)));

> p1k:=eval([x,y,z],sf[1]);

> p2k:=eval([x,y,z],sf[2]);

sf := {y = -2.127762057, z = -1.988203986, x = .720...
sf := {y = -2.127762057, z = -1.988203986, x = .720...

p1k := [.7208838583, -2.127762057, -1.988203986]

p2k := [-.4986616362, 1.683317613, 2.432648431]

Abstände

> map(sqrt,[evalf(allvalues(op(lote)))]);

[7.690095187, 2.703124206]

Zeichnung

> ku:=sphere([xk,yk,zk],sqrt(rq),style=line,color=grey):

> p:=pointplot3d([x0,y0,z0], color=blue,symbol=cross,symbolsize=40):

> p1:=pointplot3d(p1k, color=red,symbol=cross,symbolsize=40):
p2:=pointplot3d(p2k, color=black,symbol=cross,symbolsize=40):
l1 := line([x0,y0,z0], p1k, color=red):
l2 := line([x0,y0,z0], p2k, color=black):
eb:=plot3d(solve(N2,z),x=xk-sqrt(rq)..xk+sqrt(rq),y=yk-sqrt(rq)..yk+sqrt(rq),style=line,color=yellow):

> display(ku,p,p1,p2,l1,l2,eb,scaling=constrained,axes=framed);

[Maple Plot]

>

Linear Optimierung

Optimierungsaufgaben mit zwei Variablen

> restart:

> with(simplex): with(plots):

Warning, the protected names maximize and minimize have been redefined and unprotected

Warning, the names changecoords and display have been redefined

> bed:={2*x1+4*x2<=170, 2*x1+2*x2<=150, 6*x2<=180};

bed := {6*x2 <= 180, 2*x1+2*x2 <= 150, 2*x1+4*x2 <=...

Bei zwei Variablen lassen sich die Bedingungen mit plots[inequal](lineare Ungleichung) graphisch darstellen

> graph:=inequal( bed, x1=0..100,x2=0..80,
optionsfeasible=(color=grey),
optionsclosed=(color=green, thickness=3),
optionsexcluded=(color=yellow),scaling=constrained ):graph;

[Maple Plot]

Zielfunktionen zur Auswahl

> ziel:=300*x1+500*x2;

ziel := 300*x1+500*x2

ziel:=300*x1+300*x2;

ziel := 300*x1+310*x2

ziel:=300*x1+600*x2;

ziel := 300*x1+600*x2

ziel:=300*x1+602*x2;

ziel := 300*x1+600*x2

ziel:=300*x1+150*x2;

ziel := 300*x1+149*x2

> gl:=solve(ziel=q,x2);

gl := -3/5*x1+1/500*q

> ziele:=plot({seq(gl,q=seq(8*coeff(ziel,x2)*i,i=0..10))},x1=0..100,x2=0..80,color=black,scaling=constrained):#ziele;

> display(ziele,graph);

[Maple Plot]

Es ist diejenige Gerade mit dem größten x2-Achsenabschnitt gesucht, die mit dem zulässigen Bereich mindestens einen gemeinsamen Punkt.

> los:=maximize(ziel, bed );

los := {x1 = 65, x2 = 10}

> opt:=subs(los,ziel);

opt := 24500

> optg:=subs(q=opt,gl);

optg := -3/5*x1+49

> display([plot(optg,x1=0..100,color=red,thickness=3),ziele,graph]);

[Maple Plot]

>

'Probe'

> subs(los,bed);

{60 <= 180, 150 <= 150, 170 <= 170}

>

Sonderfall: Das Optimum wird längs einer Kante angenommen

> restart:

> with(simplex):

Warning, the protected names maximize and minimize have been redefined and unprotected

> bed:={2*x1+4*x2<=170, 2*x1+2*x2<=150, 6*x2<=180};

bed := {2*x1+4*x2 <= 170, 2*x1+2*x2 <= 150, 6*x2 <=...

> ziel:=300*x1+600*x2;

ziel := 300*x1+600*x2

Maple berechnet auch bei der Wahl eines Pivots durch den Benutzer die beiden möglichen Eckpunkte nicht reproduzierbar:

> alias(n=NONNEGATIVE):alias(u=UNRESTRICTED):

> sn:=setup(bed,n);

sn := {_SL1 = 170-2*x1-4*x2, _SL2 = 150-2*x1-2*x2, ...

> infolevel[all]:=1;

infolevel[all] := 1

> piveq1:=pivoteqn(sn,x1);

piveq1 := [_SL2 = 150-2*x1-2*x2]

> piv1:=pivot(sn,x1,piveq1); Z1:=subs(piv1,ziel);

piv1 := {_SL3 = 180-6*x2, x1 = -1/2*_SL2+75-x2, _SL...

Z1 := -150*_SL2+22500+300*x2

> piveq2:=pivoteqn(sn,x2);

piveq2 := [_SL3 = 180-6*x2]

> piv2:=pivot(setup(bed),x2,piveq2); Z2:=subs(piv2,ziel);

piv2 := {x2 = -1/6*_SL3+30, _SL1 = 50-2*x1+2/3*_SL3...

Z2 := 300*x1-100*_SL3+18000

>

> maximize(ziel,setup(bed),n );

> maximize(Z1,bed,u);

> maximize(Z1,piv1);

{_SL2 = 40, x1 = 25, _SL3 = 0, x2 = 30, _SL1 = 0}

{_SL2 = 40, x1 = 25, x2 = 30}

maximize:   Objective function unbounded

> maximize(ziel,bed,n);

{x2 = 10, x1 = 65}

> maximize(Z2,piv2,n );

> #maximize(Z2,piv2,u);

> #maximize(Z2,piv2);

{_SL2 = 40, x1 = 25, _SL3 = 0, x2 = 30, _SL1 = 0}

>

> maximize(ziel,bed,n,'sys' );sys;

{x2 = 10, x1 = 65}

{x2 = -1/2*_SL1+10+1/2*_SL2, x1 = -_SL2+65+1/2*_SL1...

> #setup(bed);

> maximize(ziel,setup(bed),n );#sys;

{_SL2 = 40, x1 = 25, _SL3 = 0, x2 = 30, _SL1 = 0}

> maximize(ziel,bed,u);

{x2 = 10, x1 = 65}

> maximize(ziel,bed);

{x2 = 10, x1 = 65}

> subs(%,ziel);subs(%%,bed);

25500

{170 <= 170, 150 <= 150, 60 <= 180}

> maximize(ziel,bed,n);

{x2 = 10, x1 = 65}

> subs(%,ziel);subs(%%,bed);

25500

{170 <= 170, 150 <= 150, 60 <= 180}

> #infolevel[all]:=5:

> #maximize(ziel,bed,n);

>

maximize(ziel,bed,NONNEGATIVE,'sys' ); # !! nicht reproduzierbar !!

{x1 = 65, x2 = 10}

sys;

{_SL3 = 120+3*_SL1-3*_SL2, x2 = -1/2*_SL1+10+1/2*_S...

maximize(ziel,bed,UNRESTRICTED,'sys' ); # !! nicht reproduzierbar !!

{x2 = 30, x1 = 25}

>

>

Optimierungsaufgabe mit mehr als zwei Variablen

> restart: with(simplex):

Warning, the protected names maximize and minimize have been redefined and unprotected

> Z:=53*x1+50*x2+60*x3+90*x4;

Z := 53*x1+50*x2+60*x3+90*x4

> B:={30*x1 + 22*x2 + 18*x4<=600,
10*x1 + 11*x2 + 25*x3 + 9*x4<=800,
16*x1 + 41*x4<=370,
42*x1 + 43*x3 + 37*x4<=500,
15*x1 + 23*x2 + 29*x3 + 21*x4<=700};

B := {30*x1+22*x2+18*x4 <= 600, 10*x1+11*x2+25*x3+9...
B := {30*x1+22*x2+18*x4 <= 600, 10*x1+11*x2+25*x3+9...

>

> L1:=maximize( Z, B, NONNEGATIVE, 'sys' );

L1 := {x4 = 2909730/347161, x2 = 6307455/347161, x1...

> subs(L1,Z);

666025145/347161

> subs(L1,B);

{600 <= 600, 125649225/347161 <= 800, 370 <= 370, 5...

> sys;

{_SL2 = 152079575/347161+128705/694322*_SL4+407715/...
{_SL2 = 152079575/347161+128705/694322*_SL4+407715/...
{_SL2 = 152079575/347161+128705/694322*_SL4+407715/...
{_SL2 = 152079575/347161+128705/694322*_SL4+407715/...
{_SL2 = 152079575/347161+128705/694322*_SL4+407715/...

>

Möglichkeiten zur graphischen Darstellung

Zweidimensional

> Bs:=subs(x1=0,x3=0,B),x2=0..80,x4=0..80;
#Bs:=subs(L1[3],L1[4],B),x1=0..80,x2=0..80;

Bs := {22*x2+18*x4 <= 600, 41*x4 <= 370, 11*x2+9*x4...
Bs := {22*x2+18*x4 <= 600, 41*x4 <= 370, 11*x2+9*x4...

> plots[inequal](Bs, optionsexcluded=(color=yellow) );

>

Dreidimensional

> Beq:=convert(B,equality);

Beq := {30*x1+22*x2+18*x4 = 600, 10*x1+11*x2+25*x3+...
Beq := {30*x1+22*x2+18*x4 = 600, 10*x1+11*x2+25*x3+...

> Be:=seq(isolate(Beq[i],x1),i=1..5);

Be := x1 = 20-11/15*x2-3/5*x4, x1 = 80-11/10*x2-5/2...
Be := x1 = 20-11/15*x2-3/5*x4, x1 = 80-11/10*x2-5/2...

> Bep:=map(rhs,subs(x4=0,{Be})),x2=0..80,x3=0..80;

Bep := {80-11/10*x2-5/2*x3, 140/3-23/15*x2-29/15*x3...

> plot3d(Bep,axes=normal,view=[0..40,0..40,0..40],color=grey,orientation=[-70,65]);

>

>

Transportproblem

> restart: with(simplex):

Warning, the protected names maximize and minimize have been redefined and unprotected

> kies := [220, 290, 320]:

> baustelle := [160, 330, 340]:

> kosten:=array([[10,15,18],[10,17,19],[16,19,20]]);

kosten := matrix([[10, 15, 18], [10, 17, 19], [16, ...

> x:='x':i:='i':j:='j':

> x := array(1..3,1..3):

> restr := {seq( sum(x[i,'j'],'j'=1..3)=kies[i], i=1..3)} union
{seq( sum(x['i',j],'i'=1..3)=baustelle[j], j=1..3)};

restr := {x[1,1]+x[2,1]+x[3,1] = 160, x[3,1]+x[3,2]...
restr := {x[1,1]+x[2,1]+x[3,1] = 160, x[3,1]+x[3,2]...

>

> ziel:=add(add(x[i,j]*kosten[i,j],i=1..3),j=1..3);

ziel := 10*x[1,1]+10*x[2,1]+16*x[3,1]+15*x[1,2]+17*...

> minimize(ziel, restr, NONNEGATIVE);

{x[3,2] = 0, x[1,1] = 0, x[3,1] = 0, x[2,1] = 160, ...

>

> assign(%);

> ziel;

13550

> eval(x);

matrix([[0, 220, 0], [160, 110, 20], [0, 0, 320]])

>

>

Zurück zum Inhaltsverzeichnis