(* Do not save output when exit from Mathematica *)
SetOptions[EvaluationNotebook[],NotebookEventActions -> {"WindowClose":> FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}];

Functions

Function Definition

(* Define a function *)
myFun[x_,y_] := ( x - y) ^2 /(x^2 + y^2)

(* Evaluate function *)
myFun[3,4]

(* Get the definition of the function *)
?myFun

(* Clear the function definition *)
Clear[myFun]

Operations

(* Define the function again *)
myFun[x_] := 1/x^2

(* Fund the derivative *)
D[myFun[x],x]

(* Integrate *)
Integrate[myFun[x],x]

(* Integrate over the interval *)
Integrate[myFun[x],{x,1,2}]

Clear[myFun]

Equations

(* Define function *)
f[x_] := x^2 + 2 x - 7

(* Solve equation *)
Solve[f[x] == 0, x]

(* Get numeric solution *)
N[%]

(* Get the list of the solutions *)
x/.%

(* Solve equation of forth power *)
Solve[x^4 - 5 x^2 - 3 == 0, x]

(* Sometimes even 6th power equation can be solved algebraically !*)
Solve[x^6 == 1,x]

{{x->-1},{x->1},{x->-(((-1))^(1/3))},{x->(((-1))^(1/3))},{x->-(((-1))^(2/3))},{x->(((-1))^(2/3))}}

(* Sometimes it is difficult to find the algebraic solution *)
Solve[2 - 4 x + x^5 == 0,x]

(* But you can estimate the roots using N[] function *)
N[%]

(* Often FindRoot[] function comes in handy - when we need to numerically approximate the solution, because it is hard to solve the function algebraically *)
FindRoot[Cos[x] == x, {x, 0}]

(* In certain cases equations can be solved using other functions *)
Solve[Sin[x] == a, x]

(* Solve a system of simultanious equations *)
Solve[{a x + y == 0, 2 x + ( 1 - a) y == 1}, {x,y}]

(* Simplify equation(s) *)
Reduce[a x - b == 0, x]

(* Eliminate a variable in a system of equations *)
Eliminate[{x==2+y, y==z},y]

Differential Equations

(* Solve basic differential equation *)
DSolve[y'[x] + y[x] == a Sin[x], y[x],x]

(* Given a boundary condition *)
DSolve[{y'[x] + y[x] == a Sin[x],y[0] == 0},  y[x],x]

(* Solve DiffEq and plot the result - Cornu spiral *)
DSolve[{x'[s] == Cos[t[s]], y'[s]==Sin[t[s]],
t'[s]==s,x[0]==0,y[0]==0,t[0]==0},{x,y,t},s]

ParametricPlot[Evaluate[{x[s],y[s]}/.%],{s,-10,10}]

(* Numerical solution to differential equations *)
s = NDSolve[{y'[x]==y[x] Cos[x+y[x]], y[0]==1},y,{x,0,30}]

Plot[Evaluate[y[x]/.s],{x,0,30},PlotRange->All]

(* Get specific values *)
{y[10.5],y'[12.5]}/.s