Sunteți pe pagina 1din 18

http://www.youtube.com/playlist?

list=PL6EFB5A3AFA1D8398&feature=plcp
Se deschide Wolfram Mathematica 7 for students. Din meniul principal se acceseaz opiunea
Palettes Basic Math Assistant. Pentru grafice se selecteaz opiunea Basic Commands 2D sau
3D
Funcia Solve[expresie, variabile, domeniu]
Ex:

Solve[x^2 + a x + 1 == 0, x]

Shift+Enter

Aflarea primei soluii:


Solve[x^2 + a x + 1 == 0, x][[1]]

Shift+Enter

Obs: n Mathematica, funcia exponenial e(x) se scrie Exp[x], iar constanta e = 2,71828183 se
scrie E. Aceast scriere este recunoscut i n www.wolframalpha.com

Ex:

Solve[Log[x]==Exp[x]-5, x]

Shift+Enter

In acest caz se apeleaz funcia FindRoot. Soluia va fi cutat n vecintatea unui punct:
FindRoot[Log[x]==Exp[x]-5, {x, 3}]

Shift+Enter

Plot[{Log[x], Exp[x]-5}, {x, 0, 2.5}]

Shift+Enter

6
4
2
0 .5

1 .0

1 .5

2 .0

2 .5

2
4
6
8

Din grafic se vede c mai exist o soluie n vecintatea lui 0


FindRoot[Log[x]==Exp[x]-5, {x, 0.5}]

Ex:

Shift+Enter

Gsirea soluiei n vecintatea unui punct:


FindRoot[Sin[x] + Exp[x], {x, 0}]

Shift+Enter

Plot[Sin[x]+Exp[x],{x, -1, 1}]

Shift+Enter

1 .0

Ex:

0 .5

0 .5

1 .0

Rezolvarea unui sistem de ecuaii neliniar:


FindRoot[{Exp[x - 2] == y, y^2 == x}, {{x, 1}, {y, 1}}]
ContourPlot[{Exp[x-2]==y, y^2==x}, {x, -2, 6}, {y, -1, 15}]

Shift+Enter
Shift+Enter

15

10

0
2

Din grafic se observ c mai exist o soluie n vecintatea punctului (2, 2)


FindRoot[{Exp[x - 2] == y, y^2 == x}, {{x, 2}, {y, 2}}]Shift+Enter

Ex:

Solve[a x + y == 7 && b x - y == 1, {x, y}]

Ex:

Shift+Enter

Folosirea ultimului rezultat se face prin operatorul % astfel:


fie ultimul rezultat Out[4]=
Solve[% == 0, x]

Shift+Enter

Out[5]=
-

conversia soluiei ecuatiei


N[%]

=0 n format numeric:
Shift+Enter

Obs: pentru afiarea soluiilor direct n format numeric se poate folosi funcia
NSolve[expresie, variabile]
Ex:

NSolve[x^5 - 2 x + 3 == 0, x]

Shift+Enter

radical:

Sqrt[x] sau Ctrl+2 si apoi x

scriere exponent: Ctrl+6 i apoi pentru coborrea cursorului: Ctrl+Space

Ex:

Sqrt[{2, 3, 4, 5}]

Ex:

Sqrt[2]
-

Ex:

Shift+Enter

Shift+Enter

funcia Simplify
fie ultimul rezultat Out[6]=
Simplify[%]

Shift+Enter

Grafice de funcii
Plot[f, {x, xmin, xmax}]
-

afiarea unei singure funcii pe grafic:


Plot[Sin[x], {x, 0, 6 Pi}]

Shift+Enter

afiarea mai multor funcii pe acelai grafic: Plot[{f1,f2,...fn}, { x, xmin, xmax }]


Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi}]

Ex:

Shift+Enter

colorarea ariei de sub grafic:


Plot[2 Sin[x] + x, {x, 0, 15}, Filling -> Bottom]

Shift+Enter

ContourPlot[f, {x, xmin, xmax}, {y, ymin, ymax}]


Ex:

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]

Shift+Enter

ContourPlot3D[f, {x, xmin, xmax}, {y, ymin, ymax}, {z, zmin, zmax}]
Ex:

ContourPlot3D[x^3 + y^2 - z^2 == 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

Ex:

ContourPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}]

DensityPlot[f, {x, xmin, xmax}, {y, ymin, ymax}]


Ex:

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}]

Shift+Enter

Shift+Enter

Ex:

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}, Mesh -> 10]

Ex:

Plot3D[x*E^(-(x^2+y^2))+(x^2+y^2)/20,{x,-2,2},{y,-2,2}]

Shift+Enter

Funcia Manipulate
Ex:

Manipulate[Plot3D[Sin[n x y],{x,0,3},{y,0,3}],{n,1,4}]

Ex:

Manipulate[Plot[Sin[n x],{x,0,2Pi}],{n,1,10}]

Shift+Enter

Shift+Enter

Optimizare fr restricii
<<Optimization`UnconstrainedProblems` Shift+Enter - aceast comand va ncrca un pachet care
conine cteva funcii utile.
Ex:

Plot3D[x*E^(-(x^2+y^2))+(x^2+y^2)/20,{x,-2,2},{y,-2,2}]

FindMinimum[x*E^(-(x^2+y^2))+(x^2+y^2)/20,{x,-2,2},{y,-2,2}]

ContourPlot[x*E^(-(x^2+y^2))+(x^2+y^2)/20,{x,-2,2},{y,-2,2}]

Ex:

Plot[x Sin[x + 1], {x, -10, 10}]

Shift+Enter

Shift+Enter

Shift+Enter

Shift+Enter

Aceast funcie e nemrginit jos i astfel nu are minim global. n schimb va avea o
infinitate de minime locale.
Un minim este n vecintatea lui 0.
FindMinimumPlot[x Sin[x + 1], {x, 0}]

Shift+Enter

cutarea altui minim al funciei n vecintatea lui 2


FindMinimumPlot[x Sin[x + 1], {x, 2}]

Ex:

Shift+Enter

Plot3D[Cos[x^2-3 y]+Sin[x^2+y^2],{x,-2,2},{y,-2,2}]

Shift+Enter

Minimul n vecintatea punctului (1, 1)


FindMinimumPlot[Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}]

Shift+Enter

Cutarea minimului n vecintatea punctului (1, 1) folosind metoda Newton:


FindMinimumPlot[Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}, Method -> Newton]

ContourPlot[Cos[x^2-3 y]+Sin[x^2+y^2],{x,-3,3},{y,-2,2}]

Shift+Enter

Din grafic (ContourPlot) se observ c funcia [Cos[x^2-3 y]+Sin[x^2+y^2] are i alte


puncte de minim. De exemplu un alt minim este n vecintatea punctului (-1.5, 0)
FindMinimumPlot[Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, -1.5}, {y, 0}}]

Shift+Enter

sau n vecintatea punctului (1.5, 0)


FindMinimumPlot[Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1.5}, {y, 0}}]

Shift+Enter

OPTMIZARE LINIAR
-

LinearProgramming
Problemele de programare liniar sunt probleme de optimizare n care funcia obiectiv i

constrngerile sunt liniare. Mathematica are o colecie de algoritmi pentru rezolvarea optimizrii
liniare

cu

variabile

reale,

accesai

prin

funciile:

LinearProgramming,

FindMinimum,

FindMaximum, NMinimize, NMaximize, Minimize i Maximize.


Ex:

Minx+2y
s.t.5x+y=7
x+y>=26
x >=3, y >= 4

folosind Minimize.

Minimize[{x + 2 y, -5 x + y == 7 && x + y >= 26 && x >= 3 && y >= 4}, {x, y}]

Shift+Enter

Ex: - aceeai problem folosind Nminimize


NMinimize[{x + 2 y, -5 x + y == 7 && x + y >= 26 && x >= 3 && y >= 4}, {x, y}]
Shift+Enter
Ex: - aceeai problem folosind LinearProgramming
LinearProgramming[{1, 2}, {{-5, 1}, {1, 1}}, {{7, 0}, {26, 1}}, {{3, Infinity}, {4, Infinity}}]
Shift+Enter

Optimizare local numeric neliniar


Ex:

Minimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}]

Shift+Enter

Ex: - aceeai problem rezolvat numeric


NMinimize[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}]

Shift+Enter

Funcia FindMinimum gsete minimul local. n acest caz, minimul local gsit este de asemenea
minim global.

Ex:

FindMinimum[{x - y, -3 x^2 + 2 x y - y^2 >= -1}, {x, y}] Shift+Enter

Ex:

folosind FindMinimum
ContourPlot[100/((x1)^2+(y1)^2+1)200/((x+1)^2+(y+2)^2+1),{x,
3,2},{y,3,2}]Shift+Enter

ContourPlot[100/((x1)^2+(y1)^2+1)200/((x+1)^2+(y+2)^2+1),{x,
3,2},{y,3,2},RegionFunction>Function[{x,y,z},(x^2+y^2>3)]]
Shift+Enter
(por?iuneaalb?edat?derestric?ia:x^2+y^2>3)

FindMinimum[{100/((x1)^2+(y1)^2+1)200/((x+1)^2+
(y+2)^2+1),x^2+y^2>3},{x,y}]Shift+Enter
Minim global
-

c?utareaminimuluiporninddelax=2iyimplicit:

FindMinimum[{100/((x1)^2+(y1)^2+1)200/((x+1)^2+
(y+2)^2+1),x^2+y^2>3},{{x,2},y}]

Shift+Enter

. n acest caz funcia FindMinimum a gsit un minim local.


Acest rezultat satisface condiia (restricia) problemei.
ContourPlot[- (100/((x - 1)^2 + (y - 1)^2 + 1)) - 200/((x + 1)^2 + (y + 2)^2 + 1), {x, -3, 2}, {y, -3,
2}, RegionFunction -> (#1^2 + #2^2 > 3 &), Contours -> 10, Epilog -> ({Red, PointSize[.02],
Text["global minimum", {-.995, -2.092}], Point[{-.995, -1.992}],
Text["local minimum", {0.5304, 1.2191}], Point[{1.2304, 1.2191}]}), ContourLabels -> True]
Shift+Enter

- o vizualizare 3D:
Show[{Plot3D[- (100/((x - 1)^2 + (y - 1)^2 + 1)) - 200/((x + 1)^2 + (y + 2)^2 + 1), {x, -4, 3}, {y, -4,
3}, RegionFunction -> (#1^2 + #2^2 > 3 &), PlotRange -> All], Graphics3D[{Red, PointSize[.02],
Text["Global minimum", {-.995, -2.092, -230}], Point[{-.995, -2.092, -207}], Text["Local
minimum", {0.5304, 1.2191, -93.4}], Point[{1.23, 1.22, -103.}]}]}]

Shift+Enter

Exemplu 1 Cu05-Ex.01.

reprezentarea grafic? a func?iei pe intervalele determinate


decele3restric?ii

ContourPlot[x^2+z^2+x*y+2x,{x,1.25,0},{y,0,1.25}]
Shift+Enter

ContourPlot[x^2+y^2+x*y+2x,{x,1.25,0},{y,0,1.25},RegionFunction
>Function[{x,y,z},x^2+y^21.5<=0&&x<=0&&y>=0]]

Shift+Enter

regiunea vizibil? e dat? de cele 3 restric?ii: x1^2+x2^2


1.5<=0,x<=0,y>=0.

ovizualizare3D

Plot3D[x^2+y^2+x*y+2x,{x,1.25,0},{y,0,1.25},RegionFunction
>Function[{x,y,z},x^2+y^21.5<=0&&x<=0&&y>=0]]

Shift+Enter

Minimulvafig?sitnaceast?regiune
FindMinimum[{x^2+y^2+x*y+2x, x^2+y^21.5<=0 && x<=0 && y<=0},
{x,y}]

Shift+Enter

Ex. 1-Cu0601fc

Plot3D[x*y,{x,2,2},{y,2,2}]

Shift+Enter

DE

VERIFICAT

RESTRICTIA

Plot3D[x*y,{x,2,2},{y,2,2}]

Shift+Enter

FindMinimum[{x*y,y+x*E^x==0},{x,y}]

Shift+Enter
????

ContourPlot[x*y,{x,2,2},{y,2,2},RegionFunction
>Function[{x,y,z},(y+x*E^x<=0)]]

Shift+Enter

Ampusrestric?iay+x*E^x<=0
Exemplu:

Plot[x^2*E^x,{x,4,0}]
4

Shift+Enter

1
0 .1

0 .2

0 .3

0 .4

0 .5

FindMinimum[x^2*E^x,{x,2}]

Shift+Enter

Ex.2-Cu0603fc

Plot3D[100(x2x1^2)^2+(1x1)^2,{x1,1,1},{x2,1,1}]

Shift+Enter

FindMinimum[{100(x2x1^2)^2+(1x1)^2,x1^2+x2^21<=0},{x1,x2}]
Shift+Enter

Plot3D[(x1x2)^2+2x1^2*x26,{x1,3,3},{x2,3,3}]

Shift+Enter

NUSUNTSIGURDERESTRIC?IEaparediferitin2locuri
FindMinimum[{(x1x2)^2+2x1^2*x26,x1^22x11<0},{x1,x2}]//N
Shift+Enter

minimulcuporniredela0ptx1six2

FindMinimum[{(x1x2)^2+2x1^2*x26,x1^22x11<0},{{x1,0},
{x2,0}}]//N

Shift+Enter

minimul cu pornire de la -1 pt x1 i x2

FindMinimum[{(x1x2)^2+2x1^2*x26,x1^22x11<0},{{x1,1},{x2,
1}}]//N

Shift+Enter

ANALOG cu Ex. 1-Cu0601fc (de mai sus)


Ex2. Cu0602eq

FindMinimum[{x+y,x*y12==0},{x,y}] Shift+Enter

Plot3D[(x^2y^2),{x,4,4},{y,4,4}]

Shift+Enter

FindMinimum[{x^2y^2,(x^2+y^2)20==0},{x,y}]//N

Shift+Enter

rezultatul din curs nu verifica restrictia

FindMinimum[{x1*x2*x3,x1+x2+x3==9},{x1,x2,x3}]

Shift+Enter

FindMinimum[{E^x1*(4x1^2+2x2^2+4x1*x2+2x2+1),x1^2+x2^21==0&&
x1*x210<=0},{x1,x2}]

Shift+Enter
rezultatele din curs nu verific prima

restricie
Exemplu (ultimul din curs)

Plot3D[(x+10y)/(2y^2+2y),{x,5,5},{y,10,10}]

<<Optimization`UnconstrainedProblems`

Shift+Enter

Shift+Enter

c?utarecustartdelax=1,y=1

FindMinimumPlot[(x+10y)/(2y^2+2y),{{x,1},{y,1}}]

Shift+Enter

sau
FindMinimum[(x+10y)/(2y^2+2y),{x,y}]

??????

Shift+Enter