Introduction to Mathematica

Vito, March 2017

Uses (according S. Wolfram)

Numerical and symbolic calculator
Visualization system
Programming language
Modeling and data analysis framework
Environment for developing Interactive documents: animations in general and active calculations
Accessing curated databases of everything

Class 1 - Basic calculations and plotting

Arithmetics and common functions

2+2

33/66

3 8

34-12

2^4

23^78

Sqrt[2]

Sqrt[2.]

%/Sqrt[8]

Sqrt[2]/Sqrt[8]

E/Pi

%//N

E^(I Pi)

E^I Pi

Exp[3]//N

%, %%, %%%, ... identify the last result, next to the last, two before the last, ... . 
%n identifies the result shown as Out[n].
Out[n] and In[n] are kept in memory even if you delete the line -  
you can get them back just by typing In[number of interest] or Out[number of interest]

Defining variables

Never start a variable name with a capital letter, specially a single letter

x=12

Sqrt[x]

%//N

y=2x

y=2z

alfa=x+y

anyLongVariableName=y+z

y+z

f=3x^2 + 8x -7

Clear[x]

In[-2]

f=3x^2 + 8x -7

All Mathematica functions and internal variables have names starting with a capital letter or $.
This is why we, users, use names where the first letter is not capital.
There are priority rules for homographs, but they are complicated.

Symbolic operations

FullSimplify[f]

Roots[f==0,x]

Integrate[f,x]

D[%,x]

Sum[f,{x,1,5}]

f

Plot[f,{x,0,5}]

Sum[x^i,{i,1,5}]

Sum[x^i,{i,1,Infinity}]

FindRoot[x Sin[x]Exp[x]==3,{x,1}]

Plot[x Sin[x]Exp[x],{x,-5,0}]

FindRoot[x Sin[x]Exp[x]==0,{x,-3}]

Reduce[x Sin[x]Exp[x]==0,x]

Reduce[3x^2+8x-5>0,x]

Lists

u={1,2,3}

s={a,b,c}

u s

u+s

u/s

u^2

u.s

r={x,y,z}

Clear[y]

r={x,y,z}

Cross[s,r]

a={ax,ay,az}

b={bx,by,bz}

a.b

Cross[a,b]

a b

Plot

sin=Plot[ Sin[x],{x,0,5Pi}]

tan=Plot[ Tan[x],{x,0,5Pi}]

Show[sin,tan]

Plot[ {Sin[x],Tan[x]},{x,0,5Pi}]

Plot[ {Sin[x],Tan[x]},{x,0,5Pi},PlotStyle->{Red,Blue}]

Plot[ {Sin[x],Tan[x]},{x,0,2Pi},PlotStyle->{Red,Blue},PlotRange->{-6,6}]

Plot[ {Sin[x],Tan[x]},{x,0,2Pi},PlotStyle->{Red,Blue},PlotRange->{-6,6},AxesLabel->{x,y}]

Plot[ {Sin[x],Tan[x]},{x,0,2Pi},PlotStyle->{Red,Blue},PlotRange->{-6,6},AxesLabel->{x,"response"} ]

Plot[ {Sin[x],Tan[x]},{x,0,2.5Pi},PlotStyle->{Red,Blue},PlotRange->{-6,6},AxesLabel->{x,"response"},PlotLegends->{"sine","tangent"} ]

Plot[ {Sin[x],Tan[x]},{x,0,2.4Pi},PlotStyle->{Red,Blue},PlotRange->{-6,6},AxesLabel->{x,"response"},PlotLegends->Automatic ]

f

Plot[f,{x,-3,3}]

Plot[{f,4x},{x,-3,3}]

Exercício com Plot[ ]

1) Um exercício para resolver graficamente
Os polinômios :
p1 = 4 x^3 - 8 x^2 - 15 x   e
p2 = 4 x^6 - 16 x^5 + 4 x^4 + 44 x^3 - 24 x^2 - 47 x 
são praticamente coincidentes em duas regiões contidas no intervalo - 2 < x < 3. 
Encontre essas regiões a partir dos gráficos dos dois polinômios.

Dica: Você não precisa digitar os polinômios - copie das linhas acima com Ctrl-v e devolva com Ctrl-v no lugar desejado.

Exercise with Plot[ ]

The polynomials:
p1 = 4 x^3 - 8 x^2 - 15 x   and  
p2 = 4 x^6 - 16 x^5 + 4 x^4 + 44 x^3 - 24 x^2 - 47 x 
practically coincide in two regions inside the interval [-2, 3].

Find these regions from the graphics of the polynomials.
Hint: you do not need to type the polynomials - just cut and paste from above.