Você está na página 1de 15

Breve introdução ao Mathematica

1. Informações genéricas

1.1 Avaliar células de input

Shift  Enter

Exemplo : Avaliar as células

In[1]:= Sin5

Out[1]= Sin5

In[2]:= Sin5.

Out[2]= 0.958924

In[3]:= Log.1

Out[3]= 2.30259

1.2 Ajuda com comandos e sintaxe

Usar o menu "Help" ou seleccionar a função e fazer "F1"

Ou ainda .... ? função


2 IntroMath_me.nb

In[4]:= ? Log

Logz gives the natural logarithm of z logarithm to


base e. Logb, z gives the logarithm to base b. More…

1.3 Gráficos

In[5]:= ? Plot

Plotf, x, xmin, xmax generates a plot of f as


a function of x from xmin to xmax. Plotf1, f2, ... ,
x, xmin, xmax plots several functions fi. More…

In[6]:= PlotSinAbsx, x, 2Pi, 2Pi

0.5

-6 -4 -2 2 4 6

-0.5

-1

Out[6]= Graphics

In[7]:= ? Show

Showgraphics, options displays two and three

Showg1, g2, ...  shows several plots combined. More…


dimensional graphics, using the options specified.

ShowPlotSinAbsx, x, 2Pi, 2Pi,


PlotCosAbsx, x, 2Pi, 2Pi
In[8]:=
IntroMath_me.nb 3

0.5

-6 -4 -2 2 4 6

-0.5

-1
1

0.5

-6 -4 -2 2 4 6

-0.5

-1
1

0.5

-6 -4 -2 2 4 6

-0.5

-1

Out[8]= Graphics
4 IntroMath_me.nb

In[9]:= ? Plot3D

Plot3Df, x, xmin, xmax, y, ymin, ymax generates a three

s, x, xmin, xmax, y, ymin, ymax generates a three


dimensional plot of f as a function of x and y. Plot3Df,

dimensional plot in which the height of the surface is


specified by f, and the shading is specified by s. More…

In[10]:= Plot3DSinxCosy, x, Pi, Pi, y, 2Pi, 2Pi, Mesh  False,
PlotPoints  150

1
0.5
0 5
-0.5
-1
0
-2

0
-5
2

Out[10]= SurfaceGraphics

In[11]:= ? ParametricPlot3D

ParametricPlot3Dfx, fy, fz, u, umin, umax produces a three

from umin to umax. ParametricPlot3Dfx, fy, fz, u, umin, umax,


dimensional space curve parametrized by a variable u which runs

v, vmin, vmax produces a threedimensional surface parametrized


by u and v. ParametricPlot3Dfx, fy, fz, s, ...  shades the plot

fz, gx, gy, gz, ... , ...  plots several objects together. More…
according to the color specification s. ParametricPlot3Dfx, fy,
IntroMath_me.nb 5

ParametricPlot3DCost2  Cosu, Sint2  Cosu, Sinu,


t, 0, 2Pi, u, 0, 2Pi, PlotPoints  80
In[14]:=

1
0.5
0 2
-0.5
-1
0
-2

0
-2
2

Out[14]= Graphics3D

1.4 Cálculo Numérico

In[15]:= ?N

Nexpr gives the numerical value of expr. Nexpr, n


attempts to give a result with ndigit precision. More…

In[16]:= NPi

Out[16]= 3.14159

In[17]:= NPi, 100

Out[17]= 3.1415926535897932384626433832795028841971693993751058209749445923078
16406286208998628034825342117068
6 IntroMath_me.nb

In[18]:= ? Precision

Precisionx gives the effective


number of digits of precision in the number x. More…

In[19]:= Precision2

Out[19]= 

1.5 Equações, Somas e Limites

In[20]:= ? Solve

Solveeqns, vars attempts to solve an equation or set of equations


for the variables vars. Solveeqns, vars, elims attempts to solve
the equations for vars, eliminating the variables elims. More…

Solvex ^ 3  3x ^ 2  2  0, x
 Leiam as limitações do comando Solve no Help
In[21]:=


 
Out[21]= x  1, x  1  3 , x  1  3 

In[22]:= ? Sum

Sumf, i, imax evaluates the sum of the expressions


f as evaluated for each i from 1 to imax. Sumf, i,
imin, imax starts with i  imin. Sumf, i, imin, imax,
di uses steps di. Sumf, i, imin, imax, j, jmin,
jmax, ...  evaluates a sum over multiple indices. More…

In[23]:= Sumi, i, 1, 50

Out[23]= 1275

In[24]:= ? Limit

Limitexpr, xx0 finds the


limiting value of expr when x approaches x0. More…
IntroMath_me.nb 7

In[25]:= LimitExpx, x  Infinity

Out[25]= 0

In[26]:= LimitExpx, x  Infinity

Out[26]= 

2. Listas, Vectores e Matrizes

In[27]:= vector  3, 6;

In[28]:= matrix  1, 2, 2, 2;

In[29]:= matrix  MatrixForm

Out[29]//MatrixForm=

 
1 2
2 2

In[30]:= matrix.vector

Out[30]= 15, 18

In[31]:= ? Table

Tableexpr, imax generates a list of imax copies of expr. Table


expr, i, imax generates a list of the values of expr when
i runs from 1 to imax. Tableexpr, i, imin, imax starts
with i  imin. Tableexpr, i, imin, imax, di uses steps
di. Tableexpr, i, imin, imax, j, jmin, jmax, ...  gives
a nested list. The list associated with i is outermost. More…

In[32]:= matrix  Table1  i  j, i, 1, 5, j, 1, 5;


8 IntroMath_me.nb

In[33]:= matrix  MatrixForm

Out[33]//MatrixForm=


  
6 

 


 1  

1
 
1
 
1
 
1
 
1


 7 


 

2 3 4 5


 1  
 

1
 
1
 
1
 
1
 


 8 

 
3 4 5 6


 1 

 

1
 
1
 
1
 
1
 


 

 9  

4 5 6 7


 1 


1
 
1
 
1
 
1
 

 10 
5 6 7 8

1
6
 
1
7
 
1
8
 
1
9
 

In[34]:= matrix  TableForm

Out[34]//TableForm=


1
2
 
1
3
 
1
4
 
1
5
 
1
6


1
3
 
1
4
 
1
5
 
1
6
 
1
7


1
4
 
1
5
 
1
6
 
1
7
 
1
8


1
5
 
1
6
 
1
7
 
1
8
 
1
9


1
6
 
1
7
 
1
8
 
1
9
 
1
10

3. Definição de Funções

In[35]:= fx_ : x  Exp1  x;

In[36]:= f5.

Out[36]= 6.10701

?D

In[37]:= Dfx_ : Dfy, y . y  x;  Define a derivada de f 

In[38]:= ? Integrate

respect to x. Integratef, x, xmin, xmax gives the


Integratef, x gives the indefinite integral of f with

Integratef, x, xmin, xmax, y, ymin, ymax gives a


definite integral of f with respect to x from xmin to xmax.

multiple definite integral of f with respect to x and y. More…


IntroMath_me.nb 9

In[39]:= IntegrateDfx, x

1
Out[39]=  
x x

PlotDfx, x, .5, 2


 Atenção aos eixos que o Mathematica gosta destas partidas... 
In[40]:=

0.6 0.8 1.2 1.4 1.6 1.8 2

-2

-4

-6

Out[40]= Graphics

In[41]:= Clearf

Funções definidas por ramos

In[42]:= ? If

Ifcondition, t, f gives t if condition evaluates to True, and


f if it evaluates to False. Ifcondition, t, f, u gives
u if condition evaluates to neither True nor False. More…

In[43]:= fx_ : Ifx  0, 1, 1;


10 IntroMath_me.nb

In[44]:= Plotfx, x, 2, 2

0.5

-2 -1 1 2

-0.5

-1

Out[44]= Graphics

4. Composições iterativas

Ciclos For, While e Do

In[45]:= ? For

Forstart, test, incr, body executes start, then repeatedly


evaluates body and incr until test fails to give True. More…

In[46]:= Fori  1, i  4, i , Printi

In[47]:= ? While

Whiletest, body evaluates test, then body,


repetitively, until test first fails to give True. More…

In[48]:= x  2;
Whilex  7, Printx; x  x  2

6
IntroMath_me.nb 11

In[50]:= ? Do

Doexpr, imax evaluates expr imax times. Doexpr, i, imax

values 1 through imax in steps of 1. Doexpr, i, imin, imax
evaluates expr with the variable i successively taking on the

starts with i  imin. Doexpr, i, imin, imax, di uses steps
di. Doexpr, i, imin, imax, j, jmin, jmax, ...  evaluates
expr looping over different values of j, etc. for each i. More…

In[51]:= DoPlotx  c, x, 2, 2, PlotRange  1, 8, c, 1, 5

-2 -1 1 2

-2 -1 1 2
12 IntroMath_me.nb

-2 -1 1 2

-2 -1 1 2
IntroMath_me.nb 13

-2 -1 1 2

Exercícios

Exercício

Considere as funções (matematicamente iguais)


2 sin2  ÄÄÄÄÄ 
x
1-cosx
f(x)= ÄÄÄÄÄÄÄÄ
ÄÄÄÄÄÄÄÄ
2
ÄÄÄÄÄ e g(x)= ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
2
ÄÄÄÄ
2
ÄÄÄ
x x

a. Obtenha uma representação do gráfico de cada uma das funções para valores de x pertos (mas
diferentes) de zero.

b. Construa uma tabela de valores para cada uma das funções anteriores, considerando valores de x
perto de zero.

c. Compare os resultados e comente.

fx_ : 1  Cosx  x ^ 2;


gx_ : 2Sinx  2 ^ 2  x ^ 2;
In[52]:=
14 IntroMath_me.nb

Plotfx, x, .00000001, .000002, PlotRange  All,


PlotStyle  RGBColor1, 0, 0, Thickness.009
In[54]:=

0.7

0.6

0.5

0.4

0.3

0.2

0.1

-7 -6 -6 -6
510 110 1.510 210

Out[54]= Graphics

Plotgx, x, .00000001, .00001, PlotRange  All,


PlotStyle  RGBColor0, 1, 0, Thickness.01
In[55]:=

0.5

0.5

0.5

0.5

-6 -6 -6 -6 0.00001
210 410 610 810

Out[55]= Graphics
IntroMath_me.nb 15

In[56]:= Show%%, %

0.7

0.6

0.5

0.4

0.3

0.2

0.1

-6 -6 -6 -6
210 410 610 810

Out[56]= Graphics

In[57]:= TableFormTable1.  10 ^ i, f1.  10 ^ i, g1.  10 ^ i, i, 0, 10

Out[57]//TableForm=

1. 0.459698 0.459698
0.1 0.499583 0.499583
0.01 0.499996 0.499996
0.001 0.5 0.5
0.0001 0.5 0.5
0.00001 0.5 0.5
1.  106 0.500044 0.5
1.  107 0.4996 0.5
1.  108 0. 0.5
1.  109 0. 0.5
1.  1010 0. 0.5

Você também pode gostar