Tutorial 1  Basics

One of the greatest strengths of Mathematica = M is its symbolic manipulation capabilities.  It is these symbolic capabilities that set Mathematica apart from ordinary programming languages such as C++, Fortran, Java, and Basic.  

In this notebook, we will explore just a few of the many symbolic operations in M

Getting help about commands

Help on Mathematica commands is always available through the help browser.  The browser provides several ways to access the information.  I usually select Documentation Center  from the Help menu to find the topic I need (there is a search option in the Documentation Center).
The comprehensive reference about Mathematica is the help system that is built into Mathematica itself.   

GOOGLE is better at finding help than the Documentation Center

The Help menu also shows Function Navigator (this allows you to type in the name of a function and get its documentation).  Simple approach:  Highlight an M function and then hit F1.

listy= {1,2,3,4,5,6,7,8,9,10}   (*  This is a List *)
Length[listy]

Other ways:  a)  Put cursor over the function and click on the “i Circle”
                     b)  Copy & paste it OR type it into the Help  Wolfram Documentation
                          Wolfram Documentation can provide SOME general information -- type in matrix

M functions  ~5000 of them  Go Here   (NOTE: you are reading this in your Browser NOT in M)

https://reference.wolfram.com/language/guide/AlphabeticalListing.html

Basic ideas:

capital letters for all M's functions    Sin[x]
[  ] around any variable for M's functions or your own functions:      y[x]    ArcTan[z]
{  }  Lists or ranges    vector = {x,y,z}   is also a list   this is also a list  {Bart, Sam, Carol, Suzy}
when you multiply  can use *   or a space    y*z   y z   NOT yz  (this would be a variable name for example)
Special Symbol   ×  this is the BIG ×    for times:   there is the little ×   for cross products, curls etc  Initially, obtain from a palette (see TaskBar)


Cells are blocks of text or input (code)
To generate a text cell hit Alt-7
To generate an input cell use mouse at bottom of last cell  (look for a flip of the vertical cursor to a horizontal cursor)
Comments   uses (*   *)   (*  NOTE use of ==  *)

To run a input cell  Shift Enter   OR  hit Enter on the numeric key board

Sacred Symbols    Pi   π   E   e   I    i  ∞   C    (constants of integration usually C[1] )

Dividing a cell   Control Shift d  

Merging two cells  Control Shift m     Divide and then merge this text cell right below this line.

IF you are starting to write code after working on various notebooks previously, you want to clean up the variables using ClearAll

ClearAll["Global`*"]
ClearAll["`*"]  (*  works most of the time *)

If you wish to start a new input cell:  Find the end of any cell, note cursor goes horizontal and hit enter -- you are inside a new cell

This is an input cell  Run it

"This is an input cell  Run it"  (*  Text *)

To create a text cell:  Get a horizontal cursor and then hit Alt 7

This is a text cell

Here is another input cell

(∫_0^α)(E^π)\[DifferentialD]θ

Fancied up  (traditional form)  swipe the integral below, go to Cell on the menu, hit Convert To, TraditionalForm  OR use Ctrl Shift T

(∫_0^α)(E^π)\[DifferentialD]θ

Hit Alt 7 below creating a text cell -- do so and write some text

(We’re in another text cell):  Type into an input cell (hunt downward until your cursor goes horizontal; Sometimes quicker to look at brackets on RIGHT) 
a = 2
b = 3      [ Spaces are not necessary for =, +, -, /, several other operations]
c = 5                  Evaluate (Shift Enter  OR  Enter from numerical keypad) anywhere in the cell
a+b+c

Now enter:   (note ;   semi-colon)   after evaluation but a ; after a+b+c and reevaluate
a=-2;
b=3;
c = 5;
a+b+c

REPEAT:   any line with a semicolon on the end (;) gets evaluated but is not mirrored in the output

multiplication  write 6*5    and 6 x 5

6        5     (*  any number of blank spaces between two numbers or variables is equivalent to *   AGAIN: recommend you put in the * to stay sane     *)

6* (*these words will be ignored by the kernel--you can put it inside an expression if you really want to*)5

2/3 + 3/4

Get into a Input Cell and hit 2;  then hit Ctrl /; then hit 3; then hit the -> Arrow; then hit +;  then  repeat for 3/4;   run the cell

(2/3)+ (3/4)

We can get M to evaluate this expression numerically by using N (trys to give a numerical value);
 // means apply N to (    ) after (   ) is finished being worked out (yielding 17/12); can also write N[  xxx , 40]  tries to go for 50 decimal places {more if you really want them; or less}.

(2/3 + 3/4)//N

N[(2/3+3/4)]

Do this at home:

Now type in a/b/c and evaluate:      (what appears is the output cell from executing the input cell

a/b/c

Ambiguous - How did M handle it?  Now put in parentheses to remove ambiguity (two obvious ways - do both)

(a/b)/c
a/(b/c)

Now type the following: Ctrl /  give you   (□/□)   click on the top square and hit Ctrl /   ((□/□)/□)     Then insert ((a/b)/c) and evaluate
(boxies are also available on several of the palettes- I favor “Basic Math Assistant”

((a/b)/c)

Try to figure out how to  write (a/(b/c))

(a/(b/c))

Don’t be surprised if M converts these to (a/b)/c  or a/(b/c)

Begin Again:

Solving Algebraic Equations

M can also solve algebraic equations.  Note that the equation is defined with the double equals sign ==.  This is very important.  After activating the cell, see what happens if you replace the double equals with a single equals sign.

Type in and execute:  Solve[x^3-6*x^2+11*x-6==0,x]   (*  result - an array of rules *)

Need to extract each root first we remove inner set of brackets using Flatten

Enter sol2 = Flatten[sol1,1]  {NOTE:  the line above is the same as the line above the line above}

The above is a list of rules (single set of brackets);  sol1[[1]] is the first one, etc.    So enter and evaluate: 
sol2[[1]]
sol2[[2]]
sol2[[3]]

Now we extract -- we write x/.sol2[[1]]  which means to take the rule  x-> 1 and assign it’s ‘assignment’ to x (i.e., x =1)
So enter and evaluate (we want to label each solution with a different variable)
X1 = x/.sol2[[1]]
X2 = x/.sol2[[2]]
X3 = x/.sol2[[3]]

Use Solve to apply the binomial thm i.e., solve for the values of x such that:   a (x^2) + b x + c ==0

Now extract the two solutions then take their ratio and product

Can solve simultaneous equations;  take 1.   a x + b y == c,    2.   d x + e y == f

First - a good time to clear up our variables  Use ClearAll[“`*”]   OR ClearAll[“Global`*”]; the latter goes a little deeper.
THEN:
Enter and evaluate sol= Solve[{a x + b y == c, d x + e y == f}, {x,y}]   (*  NOTE ==   and the use of  {  } *)

extract as above (AFTER YOU FLATTEN)  NOTE  instead of % we use sol to proceed

Let’s put in some numbers:

enter:
a = 2;  b = -4; c = -10; d = -8; e = 7; f = 9;
x    (* these are the values of x and y that satisfy both of the equations: {a x + b y == c, d x + e y == f}   *)
y

To get decimal values for x and y use N:   N[x]   N[y]   Try it

Try    π and e  (to get these  hit esc  p  esc     and esc  ee  esc   OR use a pallette

N[π,100]
N[E,1000]

Test the following (equality)   DOES E = e   and does Pi  π??   Use ==

Now try using ===

Test == and === with e == N[e, a big number]   do the same for ===

Try:  N[{x,y}];   Then let x = e, y = π

Most Functions will (at least attempt to) distribute on a list,  {x,y} is a list.  Vectors are lists!

Write E = m (c^2)  and evaluate it;           change E to EE or Energy  or energy or enema   just not E OR e

Now form two equations for y as a function of x  -- these represent curves y[x]

ClearAll["`*"]
sol1 = Solve[a x + b y == c, y] ;  (*  NOTE ==  *)
sol2 = Solve[ d x + e y == f, y];   (*  NOTE ==  *)
sol1 = Flatten[sol1,1]
sol2 = Flatten[sol2,1]
y1[x_] = y/.sol1[[1]]
y2[x_] = y/. sol2[[1]]

a = 2;  b = -4; c = -10; d = -8; e = 7; f = 9;
y1[x]
y2[x]
Plot[{y1[x],y2[x]},{x,0,5},PlotLegends->"Expressions"]    (* need to sub in the numbers to plot *)

somewhat circular but we can find the intercept of these two lines:

Solve[y1[x] == y2[x],x]
Flatten[%]  (*  here % only has ONE element so Flatten[%] = Flatten[%,1]  *)
x/.%
N[%]

Evaluate N[ the above number]

N[1.88889]    (* Nothing happens *)

Now do the above all in one line to find x at the intercept and then find the value of y at the intercept

sol = Solve[y1[x] == y2[x],x]  (*  I've defined an intermediate "function"  *)
interceptx =N[ x/.Flatten[sol,1]]
intercepty1 = y1[interceptx]
intercepty2 = y2[interceptx]  (* should be the same as 1 *)

Some Graphing

Swipe me -->  Plot   and then hit F1

To graph two or more functions on one graph, we create a list of functions.

Plot[{x Sin[2x], (x^3) - 3x + 1}, {x, -4, 4}]

Though this will be fine in some cases, options may be particularly helpful to clarify which graph is which .  To correspond to the list of functions, we create a list of styles.  Pay close attention here.

Plot[{x Sin[2x], (x^3) - 3x + 1}, {x, -4, 4}, PlotStyle ->  {Thickness[.01], Dashing[{.015}]}]

Note the curly braces.

Perhaps you prefer the more colorful look:

Plot[{x Sin[2x], (x^3) - 3x + 1}, {x, -4, 4}, PlotStyle -> {Hue[0], Hue[.6]}]

Or different looks for the two plots:

Plot[{x Sin[2x], (x^3) - 3x + 1}, {x, -4, 4}, PlotStyle -> {{Hue[.3], Thickness[.01]}, { Hue[.6], Dashing[{.02}]}}]

Executing the cell below will create all of the graphs.  Select the cell bracket which contains all of the graphics.  From the "Cell" menu, choose "Animate Selected Graphics."  Use the controls at the bottom left to change the speed and direction of the animation.  Click anywhere in the notebook to end the animation.  To add more detail, make the step size smaller, say .5.  (Edit the command so that the end will read {n,1,4,.5}.)

Do[Print[Plot[Sin[n x],{x,-2 π,2 π}]],{n,1,20,0.5`}]

Here, we'll use the command "Table" instead of "Do."  Also, to make interesting, inserted the "PlotRange" command.

Table[Plot[n Sin[x], {x, -6, 6}, PlotRange -> {-5, 5}], {n, 0, 4,0.1}]

MORE GRAPHICS

 Here is a plot of sin(x^3) with x ranging from -2 to 2:

Plot[Sin[(x^3)],{x,-2,2}]

Here is more complicated plot of function Exp(-x^2) Cos(20 x):

Plot[Exp[-(x^2)] Cos[20 x],{x,-2,2}]

This plot gives the probability density for an excited state of a quantum mechanical harmonic oscillator. 
Here  HermiteH[6, x]  evaluates  the 6-th Hermite polynomial.

Plot[(((HermiteH[6,x] Exp[-((x^2)/2)]))^2),{x,-6,6}]

Mathematica chooses appropriate scales for plots, even when there are singularities:

Plot[(1/(Sin[x])),{x,0,10}]

You can give a list of functions to plot:

Plot[{BesselJ[1,x],BesselJ[2,x],BesselJ[3,x]},{x,0,15}]

You can also use Mathematica to make parametric plots.
In a parametric plot, you give both the x and y 
coordinates of each point as a function of the 
third parameter, say t. Here is the curve made 
by taking the x coordinate of each point to be sin(t)
and the y coordinate to be sin(2t)

ParametricPlot[{Sin[t],Sin[2 t]},{t,0,2 π}]

This gives a plot in polar coordinates, with  
rho(t)  as the radius function at angle t:

rho[t_]:=(1/2) (3 ((Cos[t])^2)-1);
ParametricPlot[{rho[t] Cos[t],rho[t] Sin[t]},{t,0,2 π}]

This makes a contour plot of the function  sin(x) sin(3y):

ContourPlot[Sin[x] Sin[3 y],{x,-2,2},{y,-2,2},Contours->20]

This gives a rectangular array of values. The array is quite 
large, so we end the input with a semicolon to stop the 
result from being printed out:

s=Table[Mod[j,i],{i,20},{j,20}];

This gives a density plot of the array of 
values containing in s:

ListDensityPlot[s]

Mathematica can also make three-dimensional pictures.
Here is the plot of the function sin(x y) for 
x and y between 0 and Pi:

Plot3D[Sin[x y],{x,0,π},{y,0,π}]

Here is 3D-picture of a cylinder:

Show[Graphics3D[Cylinder[]]]

Here is 3D-picture of a cone:

Show[Graphics3D[Cone[]]]

Here is 3D-picture of a Moebius strip:

ExampleData[{"Geometry3D","MoebiusStrip"}]

Here is 3D-picture of a Torus  -- M has to find it; maybe sitting in Illinois

ExampleData[{"Geometry3D","Torus"}]

Here is picture of a piece of wood  -- Again, M has to find it; maybe sitting in Illinois

ExampleData[{"Texture","Wood"}]

Mathematica can also plot a data list:

s=Table[{x,x Cos[x]},{x,-4 π,4 π,(π/20)}];
ListPlot[s,Joined->True]

This makes a three-dimensional plot of an array of values:

s=Table[N[Exp[-(x^2)-(y^2)]] N[Cos[5 (Sqrt[(x^2)+(y^2)])]],{x,-2,2,0.1},{y,-2,2,0.1}];
ListPlot3D[s,PlotRange->All]

Here is the plot of the function sin(x) sin(3y) for x and y between -2 and 2:

Plot3D[Sin[x] Sin[3 y],{x,-2,2},{y,-2,2},PlotPoints->30]

This redisplays the surface, as would it be seen from  a different view point (Play with ViewPoint)

Plot3D[Sin[x] Sin[3 y],{x,-2,2},{y,-2,2},PlotPoints->30,ViewPoint->{0,1,1}]

Here is an example of a curve in space,  specified by a single parameter:

ParametricPlot3D[{Sin[u],Cos[u],(u/3)},{u,0,15}]

Here is a sphere, generated from a parametric representation:

ParametricPlot3D[{Sin[u] Cos[v], Sin[u] Sin[v], Cos[u]},
{u, 0, Pi}, {v, 0, 2 Pi}]

The definition and a picture of octahedron:

PolyhedronData["Octahedron"]

The definition and a picture of dodecahedron:

PolyhedronData["Dodecahedron"]

You can Stellate your favorite polyhedron

<<PolyhedronOperations`;
Stellate[PolyhedronData["Octahedron"]]

PostFix    == //

(x^2 - Exp[x])//(x=2)     (*  // says shove 2 in for x on the expression contained in (   ) and evaluate it.
                                    // is called PostFix    *)  
x   (*to show you that x now = 2; see next cell *)

Clear[x]  (*  this is a precaution; otherwise, until reassigned, x stays == 2   CAUSE OF MANY ERRORS USING M  *)
x
3^100
N[%]   (*  OK, take note:   (1) N tries to give you a number for whatever you put in the (2) brackets [  ]
             in a useful format;   (3)  % stands for whatever sits in the last output line above  *)

Sqrt[2]     (*as is this holds the answer but no evaluation *)
N[Sqrt[2]]   (* this evaluates to some fixed no. of default digits *)
N[Sqrt[2],50]  (* this gives you 50 digits;    play with it in another notebook  Ctrl n gets you one; change 50 to 2000*)
√12    (* I used Esc sqrt Esc;   gives exact value   *)

Here is  the formula for a indefinite integral; running the cell evaluates the integral (to within a constant NOT SHOWN).
I am using the Palettes to make this.  You could also write:  Integrate[x^4/(x^2-1),x]--same results

∫((x^4)/((x^2)-1))\[DifferentialD]x
Integrate[x^4/(x^2-1),x]

Here is a more complicated indefinite integral:  (what's a PolyLog???)

∫(x/(c+Exp[x]))\[DifferentialD]x

Mathematica can find a closed form for some sums with 
indefinite number of members using Gosper's summation algorithm. 
For example, here the letter n is the number of members in the sum, 
and we can find:

(∑_(k=1)^n)(k^2) (1+k)

We can find the explicit formula for the definite integral and then get a numerical value using N[%] 
% == Previous result

(∫_2^5)(1/((x^3)-1))\[DifferentialD]x
N[%]

Mathematica knows the derivatives of all standard mathematical functions:

(∂_x)ArcTan[x]
D[ArcTan[x],x]

(∂_(x,x))ArcTan[x]
D[ArcTan[x],{x,2}]  (* note the 2 *)
(∂_x)((∂_x)ArcTan[x])

Define a function f.  Then create a table and display is using "TableForm" which will show the ordered pairs (x, f(x)) for 0 ≤ x ≤ 5 by steps of 0.2.

Clear["Global`*"];
f[x_] := (x^(-2));
inversesquares =Table[{x,f[x]}, {x,1,20,0.1}]
ListPlot[inversesquares,PlotRange-> {0,1}]

Use of Solve to solve three simultaneous equations for the variables x,y,z
a x + b y + c z  = d 
e x + f y +g z  = h
j x + k y + l z  = m

Solve[{a x + b y + c z == d, e x + f y +g z== h, j x + k y + l z == m}, {x, y, z}]

There are two basic methods of showing colors.  The first uses Red, Green, and Blue.  ("Log" refers to the natural logarithm.)

Plot[x Log[x+2], {x, -1.99, 3}, PlotStyle -> RGBColor[0, .4, .6], PlotRange->{-2,8}]

A second way to show a graph in color is by using Hue[k].  One example is shown.  Try other values for k between 0 and 1, remembering your rainbow.

Plot[x Log[x+2], {x, -1.99, 3}, PlotStyle -> Hue[.39],PlotRange->{-2,8}]

A mathematical torus:

ParametricPlot3D[{(8+3 Cos[phi]) Cos[theta],(8+3 Cos[phi]) Sin[theta],3 Sin[phi]},{theta,0,2 π},{phi,0,2 π}]

Here is a three-dimensional plot of the Rieman zeta function zeta(z) in the complex plane. 
The height of the surface is given by  Abs(zeta(z)).  The color is related to the phase of zeta(z).

Plot3D[Abs[Zeta[x+I y]],{x,-2,6},{y,2,35},PlotPoints->30]

More 2D -- Parametrics

Primarily, one needs to enter the functions x = f(t), y = g(t) as a list of functions.  Beyond that, the coding for parametrically defined graphs should be fairly clear. Below -- inserted "AspectRatio -> Automatic" to make the x- and y-scales equal.

ParametricPlot[{Cos[t], Sin[ t]}, {t, 0, 2π},AspectRatio->Automatic]

Checking results

First we'll define a function f.

f[x_]:=x^4 +12x^3 - 305x^2 - 1056x + 3220

Let's call our solution set "solns."

solns = Solve[f[x] == 0, x]

Use TableForm to display the output.  Here, this really isn't necessary because the numbers are quite nice.  Sometimes, however, the answers are much easier to read in this format.

Check these values by replacing them into the function.

solns
f[x] /. solns

This shows one of the reasons that Mathematica shows the solution set in this format - to make substitution (into any equation) quite easy.  Then clear both f and solns.

Clear[f, solns]

Repeat the same steps above using "NSolve" with the function f(x) = (x^4)-6(x^3)+ 3x + 8. When you are done, clear your function and the name of your solution set.  (Alternatively, one can simply refer to the previous output rather than naming the solution set.)

Out of order?

Did you make a mistake somewhere so that "%" or even "%%"  just won't work? See if this scenario sounds familiar:  You made a spelling error in an input line with a "%".  You correct the spelling only to try to execute the corrected command on the faulty output.  When this occurs, replace the "%" with Out[ ],   putting the number of the proper output line in the square brackets.

Another method

The command "FindRoot" uses an iterative process called Newton's Method, and it requires an initial input which is fairly close to the actual root being sought.  Let's deal with the equation  x - Cos[x] == 0.

FindRoot[x - Cos[x] == 0, {x, 1}]

As another example, consider the cubic f(x) = (x^3)+5(x^2)-7. First, we'll define the function, calling it f.  (How clever!)

f[x_]:=(x^3)+5(x^2)-7
Plot[f[x],{x,-6,2}]

Plot the function.  Choose an appropriate domain so that you can see the three roots.

Since the smallest root is near x = -5, we'll use FindRoot and Newton's Method with this as an initial guess.

FindRoot[f[x] == 0, {x, -5}]

Based on your plot above, choose nice x-values as initial estimates to find the other two roots.  Note that bad choices for initial inputs (too far away, past a max or min, for example) can lead to some unexpected results.

Clear[f]

Systems

Here, we will solve a system of two equations, y = 2x - 3 and (x^2)-5x+2xy+(y^2)=6. First, we will graph the system to check for approximate solutions.  We will use a new method to do this. Before this can be done, use "Help" and load the package "ImplicitPlot."  Execute the cells to name and plot each of the graphs separately.

gr1=ImplicitPlot[(x^2)- 5x + 2x y + (y^2)== 6, {x, -4, 5}]

gr2 = Plot[2x - 3, {x, -3, 4}]

The interesting part is to combine the two graphs.  Use the command "Show."  Note that the graph shown is on the intersection of the two domains given.

Show[gr1, gr2]

To solve, we need a list of equations and a list of variables for which we wish to solve.

NSolve[{(x^2)-5x + 2x y + (y^2)==6, y == 2x -3}, {x, y}]

Plot3D[Sin[x y], {x, -3, 3}, {y, -3, 3},PlotPoints->60,ColorFunction->Hue]

Plot3D[Exp[1 - (x^2)+(y^2)], {x, -7, 7}, {y, -3, 3},PlotPoints->60,ColorFunction->Hue]

Plot3D[Cos[(x^2)+(y^2)], {x, -3, 3}, {y, -3, 3},PlotPoints->60,ColorFunction->Hue]

Plot3D[Sin[((Abs[x])/(Cos[y]))],{x,-1,2},{y,-1,1},PlotPoints->35,ColorOutput->GrayLevel]

ContourPlot[Cos[(x^2)+(y^2)], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 25]

ContourPlot[Cos[(x^2)+(y^2)], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 25,ContourShading->False]

DensityPlot[Cos[(x^2)+(y^2)], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 50]

Plot3D[y/(x^3),  {x, -1, 1}, {y, -1, 1}]
Plot3D[y/(x^3),  {x, -1, 1}, {y, -1, 1},ViewPoint->{1.178, -1.274, 2.905}]
Plot3D[y/(x^3),  {x, -1, 1}, {y, -1, 1},ViewPoint->{2.605, -1.927, 0.975}]

On any of these graphs, it is also possible to change the point of view.You may have noticed in the options that the default "ViewPoint" is (1.3, -2.4, 2).Adding the option in the command line with alternate numbers is one way to change this, but there' s another method which is usually more fun.In any of the inputs above, place a comma inside the final closing bracket and leave the cursor there.From the "Input" menu, choose "3D ViewPoint Selector..." Put the cursor on the box, click, and drag it as desired.When you get to a position you like, release the mouse, and click on "Paste." The ViewPoint option will be entered automatically.Then execute the cell to see what you did! (Of course, if you prefer, you are welcome to use the drag bars or enter specific numbers in either spherical or cartesian form instead.)

ParametricPlot3D[{Cos[2t], Cos[t], Sin[3t]}, {t, 0 , 2π}]

If you' re confident, then the first thing to do is to load a special package.Under "Help," choose "Add-Ons." Then choose "Standard Packages," "Graphics" and "Animation." Execute the appropriate cell to load the package.After doing this, execute the following :  Can' t get this to work.

Clear["Global`*"];
<<Graphics`Animation`
SpinShow[Plot3D[Sin[x+Sin[y]], {x, -3, 3}, {y, -3, 3}], Frame -> 12]

Use Play or ListPlay to create a sound; to play--double click on the graphics

Plot[Sin[10000/t],{t,0,2}]
Play[Sin[10000/t],{t,0,2}]

Limits

Limit[((Sin[x])/x), x->0]

Limit[((2(x^3)-4x)/((x^3)+1)), x-> ∞]

Limit[1/x, x->0, Direction->1]
Limit[1/x, x->0, Direction->-1]
Plot[1/x,{x,-1,1}]
Plot[((Sin[x])/x),{x,-1,1}, PlotRange->{0,1}]

Hard way to take deriviatives and then easy way.

Limit[((Tan[x+h]-Tan[x])/h), h->0]
D[Tan[x],x]

Derivatives

Be sure to indicate the variable in each case.  (Note that this is one of the few cases where Mathematica does not require the full English word for the command.)

Compare use of D and the usual Limit definition of a derivative.  δx = Δx
after writing the code below:   esc d esc gives you δ;  esc del esc gives you ∇

ClearAll["Global`*"]
y[x_] := Exp[-x] ( (x^2) - 1);
D[y[x],x];
dy[x_] = Simplify[%];
Plot[{y[x],dy[x]},{x,-5,5}]
 Limit[((y [x+ δx]- y[x] )/(δx)),δx-> 0];
dylim[x_] = %
Simplify[dylim [x]]== dy[x]

D[x Log[x], x]
y[x_] := x Log[x]
y'[x]
D[y[x],x]

Find the next derivative and then simplify the result to see the more familiar form.

D[f[x]/g[x], x]

D[-(1/2) g (t^2)+(Subscript[v, 0]) t + (Subscript[s, 0]), t]

To find the third derivative, (((d^3)y)/(dx^3)), the coding at the end changes as follows.

D[Tan[x], {x, 3}]
z[x_] := Tan[x]
z'''[x]

Alternatively, once can define a function first and then use more standard notation.

f[x_]:=Sin[Sin[Sin[x]]]

f'[x]

f''[x]

On the palette, for the familiar derivative in single-variable calculus, use (∂_□) □.

(∂_x) ArcTan[x]

For multivariable functions, use (∂_(□,□))□.  Note that the parentheses are necessary.

(∂_(x,y))((x^3) (y^4))

f[x_]:=Sin[Sin[Sin[x]]]
(∂_x) f[x]

f[x_] = (x^(Log[x]))   (* type in x and then use ctrl 6  *)  
diffy = (∂_x)(f[x])  (* hit esc pd exc Ctrl -  NOTE no brackets  could use (  )  *)
(∂_y) f[x]

Plot[{f[x],diffy},{x,.1,2},PlotLegends->True]

Plot[{f[x],diffy},{x,.1,2},PlotRange->{{0,2},{-20,20}},PlotLegends->"Expressions"]

Implicit functions

Implicitly-defined functions require some special care.  First, we'll name our equation.

equat1 = (x^3)- 4 x y + (y^2)==12

We can't take a derivative with respect to x yet, since Mathematica would interpret y as a constant.  We must first express y as f[x]. 
NOTE--ReplaceAll:  expr /. rules applies a rule or list of rules in an attempt to transform each subpart of an expression expr; so below in equat1 it says to  replace y with f[x] (defined above) everywhere in equat1.  ANOTHER WAY to say it:  substitute in for y (everywhere) the value f[x].

equat1/.y->f[x]

Then differentiate and solve for f'[x].     NOTE %  == Out[] -- take previous OUT and put it where you have typed in %   NOTE2--Solve below did nothing

D[%,x]

Solve[%, f'[x]]

A max-min problem

Consider the function y = cos(x) over the interval (-π/2, π/2).  Find the area of the largest rectangle which may be constructed with two vertices on the x-axis and the other two vertices on the graph of the function.

First, we'll draw a picture to help understand the problem a little better, beginning with the graph of cos(x).

grcosx = Plot[Cos[x], {x, -2, 2}]

The next group of commands give something new.  We construct a typical rectangle and then show the rectangle and the graph together.

rect = {GrayLevel[.5],Rectangle[{-1.1,0},{1.1, Cos[1.1]}]};
Show[{Graphics[rect], grcosx}, Axes -> True]

We now define the area function, where the base is 2x and the height is Cos[x].

areaofrect[x_]:=2x Cos[x]

Find the derivative, and solve for the stationary point. Here, the FindRoot command will be appropriate.

FindRoot[areaofrect'[x]==0, {x, 1}]

Substitute this value of x to find the area.

areaofrect[x]/.%

rect = {GrayLevel[.5],Rectangle[{-0.860334,0},{0.860334, Cos[0.860334]}]};
Show[{Graphics[rect], grcosx}, Axes -> True]

Mathematica uses the chain rule to simplify derivatives:

(∂_x)(2 x f[(x^2)])
(∂_x)(2 x )*f[(x^2)]+ 2 x *(∂_x)f[(x^2)]

This constructs the sum:

(∑_(j=1)^22)((x^j)/j)

Mathematica gives the exact result for the following sum:

(∑_(j=1)^20)(1/(j^3))

Here is the numerical value of the previous sum value to a desired precision 
(a lot of times we only want a few decimal places).

N[(∑_(j=1)^20)(1/(j^3)),10]

Product works just like Sum:

(∏_(j=1)^9)(x+j)

This finds the limit of  (sin(x)-x)/x^3  as x approaches 0:

Limit[((Sin[x]-x)/(x^3)),x->0]

You can also find approximative formulae.  This computes the power series expansion of exp(-x)*sin(2x)  
about the point x=0 up to order x^6:

s=Series[Exp[-x Sin[x]],{x,0,6}]

Convert to a normal expression (drops the Order of higher terms):

Normal[s]

We can integrate or differentiate such power series, for example, we compute here the integral of series s:  
where by running the cell above you have defined s = Series[Exp[-x Sin[x]], {x, 0, 6}]; by just "asking for s"
you can see that it is defined; then we integrate it

s
∫s\[DifferentialD]x

Series[Tan[x],{x,0,5}]
InverseSeries[Series[Tan[x],{x,0,5}]]
Series[ArcTan[x],{x,0,5}]

You can use the function DSolve to find symbolic solutions of ordinary differential equations. 
Here we solve one differential equation:

DSolve[y'[x]+y[x]==1,y[x],x]

This solves two simultaneous differential equations:

DSolve[{y'[x]==-z[x],z'[x]==-y[x]},{y[x],z[x]},x]

You can add boundary conditions for differential equations 
by explicitly giving additional equations such as y[0] = 0. 
Here we solve boundary value problem  
z'[x] + y[x] = 1 - x*x,  y'[x] = z[x],  z[0] = 0,  y[1] = 0:

DSolve[{z'[x]+y[x]==1-x x,y'[x]==z[x],z[0]==0,y[1]==0},{y[x],z[x]},x]

You can evaluate the numerical value of multidimensional integrals 
(you fall back on numerical solutions when the exact solutions don't work!); consider the 2D function:
z = Sqrt[2. + x + y^2 + (x y)^3]

ClearAll["Global`*'"]
Plot3D[(Sqrt[2.+x+(y^2)+(((x y))^3)]),{x,0,1},{y,-1,1},PlotRange->{0,2.2}]
NIntegrate[(Sqrt[2.+x+(y^2)+(((x y))^3)]),{x,0,1},{y,-1,1}]

Noting that this function is pretty flat.   The integral ~ (xy Area) * (average height above x-y plane);  eyeballing the latter at ~ 1.7, and taking xy Area = 1.0 * 2.0 == 2.0, we come pretty close:

IntegralApproximate = 1.7 * 2.0

Mathematica can compute the numerical value of an infinite sum, for example:

NSum[(1/(j^3)),{j,1,∞}]

Here we find a root of a Bessel function near x=10.5:

FindRoot[BesselJ[0,x],{x,10.5}]

Below we generate a table of the numerical values  of the exponential function:

data2 = Table[{x,Exp[(x/5.)]},{x,7}]
data=Table[Exp[(x/5.)],{x,7}]
plotty = ListPlot[data,PlotRange->{0,5}, PlotStyle->PointSize[0.02]]

Here we find a least-squares fit to data of the form c1+c2*x+c3*x^2:

fitdata1 = Fit[data,{1,x,(x^2)},x]
fitty1 = Plot[%,{x,0,7},PlotRange->{0,5}, PlotStyle->{Red,Thickness[0.01]}]

1.09428497470253716`+0.0986337275820518044` x+0.0459481907679247836` (x^2)

Using 'Fit' we find a fit of the form  c1 + c2*x + c3*x^3 + c4*x^5;   let's plot all of them together

fitdata2 = Fit[data,{1,x,(x^3),(x^5)},x]
fitty2 = Plot[%,{x,0,7},PlotRange->{0,5}, PlotStyle->{Purple,Thickness[0.01]}]
Show[plotty, fitty1, fitty2,Frame-> True]

We can fit multidimensional data, for example, 3D Consider a variable such as charge density that depends on position in 3D:   ρ[x,y,z]  (can't really plot it.  listy3D is a numerical list representing a few points (here:  10}, say, of the form{x, y, z, ρ[x,y,z]}.

We fit these values of ρ[x,y,z] with a general second order expansion in x,y,z  represented by:   

{1, x, y, z, x^2, y^2, z^2, x y, x z, y z}.

ClearAll["Global`*'"]
listy3D = {{0.1, -3.1, 2.7, 2.13}, {0.2, -3.3, 2.9, 3.57}, {0.3, -3.4, 3.8, 3.63}, {0.4, -3.5, 3.9, 4.38}, 
{0.5, -3.6, 4.7, 7.23}, {0.6, -3.7, 5.1, 5.34}, {0.7, -3.8, 8.9, 4.39}, 
{0.8, -3.9, 9.3, 8.64}, {0.9, -4.0, 5.3, 3.24}, {1.2, -4.2, 3.2, 1.27}};
listylisty = listy3D[[All, 4]]
h[x_,y_,z_] = Fit[listy3D, {1, x, y, z, x^2, y^2, z^2, x y, x z, y z}, {x, y, z}]
LL = Length[listy3D];
fitlisty={0,0,0,0,0,0,0,0,0,0};
For[i = 1, i <= LL, i++, fitlisty[[i]]= h[listy3D[[i]][[1]], listy3D[[i]][[2]],listy3D[[i]][[3]]]]
fitlisty

Now we do a 1D plot to compare the fitted values (in fitlisty) with the original data (in listy3D)

plottyfitlisty = ListPlot[fitlisty, PlotStyle->{Red,PointSize[0.02]}]
plottylisty3D = ListPlot[listylisty,PlotStyle->{Blue,PointSize[0.02]}]
Show[plottyfitlisty,plottylisty3D]

Not a bad fit.

Below gives another table of  {x, y}  pairs:

data=Table[{x,Exp[Sin[x]]},{x,0.,1.,0.2}]

Here we find a fit to the new data set, of the form  c1+c2*sin(x)+c3*sin(2x)

Fit[data,{1,Sin[x],Sin[2 x]},x]

Below we find a numerical approximation to the minimum of the function: x*sin(x) close to  x = 2 Pi.   
The result is a list: the first entry is the minimum value of the function; the second entry
 is the point  at which the minimum occurs.

FindMinimum[x Sin[x],{x,2 π}]

You can also search for a local minimum in a function of several variables:

FindMinimum[(((1+2 x-y+3 z))^2)+(((x+y-z))^2)+(((3 x-z))^2)+(((x+y+z))^2),{x,1},{y,0},{z,-1}]

M can find with Constrained Minima; the constraints are given after the function in {   };  for example:

Minimize[1+2 x-3 y+8 z,{1<=x,x<=5,1<=y,y<=3,4<=z,z<=5,x+7 y<=10},{x,y,z}]