(* TUTORIAL BASICO (Para Ejecutar instrucción: shift+enter) *)

1+1

a=1+1;

a

{2+3,2-3,2*3,2  3, 2/3,2./3,2^3,Sqrt[2],Sqrt[2.],2^(1/2), 2 ^(1./2)}

N[Sqrt[2],2000]

{Pi,E}

N[Pi,2000]

N[E,1000]

3!

100!

N[100!]

1000!

N[1000!]

Plot[{Sin[x],Cos[x]},{x,-2 Pi,2 Pi},PlotStyle->Thick]

Plot[{Sin[x],Cos[x]},{x,-2 Pi,2 Pi},PlotRange->{{-2*Pi,2*Pi},Automatic},Frame->True,FrameStyle->Thick,PlotStyle->{Thick,{Thick,Dashing[{0.02,0.02}],RGBColor[0.8,0,0.2]}},
AxesStyle->Medium,FrameLabel->{StyleForm["α",16],StyleForm["f(α)",16]}]

??pl

pl[f1_,f2_]:=Plot[{f1[x],f2[x]},{x,-2 Pi,2 Pi},PlotRange->{{-2*Pi,2*Pi},Automatic},Frame->True,FrameStyle->Thick,PlotStyle->{Thick,{Thick,Dashing[{0.02,0.02}],RGBColor[0.8,0,0.2]}},
AxesStyle->Medium,FrameLabel->{StyleForm["α",16],StyleForm["f(α)",16]}];

g[x_]:=Cos[x]^2;pl[Sin,g]

Sin'[x]

D[Sin[x],{x,1}]

Exp[r*x]

D[Exp[r*x],x]

D[Exp[r*x],{x,22}]

Integrate[Sin[x],x]

∫Sin[x] \[DifferentialD] x

Integrate[Sin[x],{x,0,Sqrt[2]*Pi/2}]

NIntegrate[Sin[x],{x,0,Sqrt[2]*Pi/2}]

Integrate[Exp[-x^2],x]

NIntegrate[Exp[-x^2],{x,0,1}]

N[(1/2) (Sqrt[π]) Erf[1]]

Series[Cos[x],{x,0,4}]

Series[Exp[-x^2/1.],{x,0,44}]

Series[Cos[x],{x,0,14}]

Integrate[Exp[-x^4],x]

pn[x_,n_]:=Normal[Series[Sin[x],{x,0,n}]];

pn[x,3]

pn[x,21]

p1=pn[x,1];p3=pn[x,3];p21=pn[x,21];Plot[{Sin[x],p1,p3,p21},{x,-4*Pi,4*Pi},PlotRange->{{-4*Pi,4*Pi},{-2,2}},PlotStyle->Thick]

(* Series *)

a=.;Sum[1/a^n,{n,{1,4,10}}]

Sum[1/a^n,{n,4}]

Sum[1/a^n,{n,2,6,2}]

Sum[1/n,{n,10}]

Sum[1./n,{n,10}]

Sum[1./n,{n,Infinity}]

Sum[1/n!,{n,0,Infinity}]

p=.;Sum[1/n^p,{n,Infinity}]

Plot[Zeta[p],{p,-3,10}]

{Sum[1/n^2,{n,Infinity}],Zeta[2]}

sm[m_]:=N[Sum[1/n^2,{n,m}]];

a=Pi^2/6;ListPlot[{Table[{m,a},{m,100}],Table[{m,sm[m]},{m,100}]},PlotRange->{{0,100},{0.5,1.8}}]

Sum[(-1)^(n+1)/n,{n,Infinity}]

Clear[f,x];f[x_]:=If[x<0,Sin[x],Sin[x]+x/10];Plot[f[x],{x,-30,30},PlotStyle->Thick]

f=.;x=.;Clear[c];g[c_]:=(f[x_]:=If[x<c,Sin[x],Sin[x]+Sin[x]+x/10];Plot[f[x],{x,-30,30},PlotStyle->Thick]);

g[14]

Plot3D[Sin[x*y],{x,-3,3},{y,-3,3}]

(* Vectores, Matrices, Autvalores (Eigenvalues) y Autovectores (Eigensystem) *)

mf[au_]:=MatrixForm[au]

Clear[a,b,c];vec={a,b,c}

vec.vec

vec*vec

Tr[vec]

Tr[vec,Times]

mat={{1,1,1},{1,-1,2},{2,0,3}};

mf[mat]

mat//mf

Transpose[mat]//mf

Det[mat]

Inverse[mat]

matr=RowReduce[mat]

matr//mf

mat[[1,All]]

mat[[All,1]]

mat[[3,1]]

mat[[3]]

MatrixRank[mat]

Clear[x,y,z];Solve[{x+ y+z==a,x-y+2z==b,2 x+3 z==c}]

Clear[a,b,c,x,y,z];Solve[mat.{x,y,z}=={a,b,c}]

matinv=Inverse[mat]

mat

p=Det[mat-IdentityMatrix[3] x]

z=Eigenvalues[mat]

Solve[p==0,x]

NSolve[p==0,x]

Eigensystem[mat]

{z,zv}=Eigensystem[mat]

z

zv

zv[[1]]

mat.zv[[1]]

mat.zv[[1]]-z[[1]] zv[[1]]

s=Transpose[zv]

s//mf

si=Inverse[s]

si//mf

matd=si.mat.s

matd//mf

si.s

si.s//mf

??Eigensystem

??JordanDecomposition

(* Ejemplo de Matriz no diagonalizable *)

ma={{2,1},{-4,-2}};

ma//mf

Eigensystem[ma]

{s,j}=JordanDecomposition[ma]

j//mf

si=Inverse[s];si.ma.s

{u,d,v}=SingularValueDecomposition[ma]

u.d.Transpose[v]

Transpose[u].ma.v

a:=Table[Random[],{i,n},{j,n}];

n=4;a//mf

n=10;a=Table[Random[],{i,n},{j,n}];a=(a+Transpose[a])/2;

a//mf

a[[1]]

a[[1,All]]

a[[All,1]]

{z,zv}=Eigensystem[a];s=Transpose[zv];si=Inverse[s];si.a.s//mf//Chop

z

s//mf

{Tr[a],Tr[z]}

{Det[a],Tr[z,Times]}

si=Inverse[s];s.si//mf

a2=a.a;a2//mf

a2p=s.DiagonalMatrix[z^2].si;a2p//mf

a2-a2p//mf//Chop

(* Gram Schmidt: partiendo de vec, gs genera vectores ortogonales en v y ortonormales (normalizados) en vn *)

Length[zv]

zv[[1]].zv[[2]]

zvn=Orthogonalize[zv];

zvn[[1]].zvn[[2]]//Chop

Clear[vec,v];gs:=(v=vec;vn=v;le=Length[vec];Do[v[[i]]=vec[[i]]-If[i==1,0,Sum[(v[[j]].vec[[i]]/len[j])*v[[j]],{j,i-1}]];len[i]=v[[i]].v[[i]];vn[[i]]=v[[i]]/Sqrt[len[i]],{i,le}]);

vec={{1,1,1},{1,1,2},{1,2,1}};

gs;v

v.Transpose[v]

vn

vn.Transpose[vn]

(* Orthogonalize: Instrucción que directamente genera vectores ortonormales *)

Orthogonalize[vec]

(* Ejercicios *)

"1) Encontrar los polinomios de Taylor alrededor del origen de la función 
 Exp[-x^2/10] Cos[x], de grado 2, 4,10, y 40;
Graficar la funcion y los poliniomios entre -2 Pi y 2 Pi;


2) Generar una matriz simétrica m de 10 x 10 con elementos aleatorios entre 
0 y 1  y diagonalizarla. Encontrar 
a) Sus autovalores,
b) Sus autovectores normalizados 
c) Una matriz s tal que st.m.s = d, con d diagonal, verificando el resultado. 
d) m^12, mediante dos métodos distintos, comprobando el resultado.  
e) Det[m], mediante dos métodos distintos, comprobando el resultado. 
f) Tr[m], mediante dos métodos distintos, comprobando el resultado. 
g) La inversa de m, en caso de que exista, mediante dos métodos distintos, comprobando el 
resultado. 

3) Idem 3) para una matriz m de 100 x 100 construida del igual forma. 

4) a) Generar 10 vectores de (Superscript[R, 15]) con elementos aleatorios entre 0 y 1. 
 b) Comprobar si son linealmente independientes 
 c) Determinar una base ortogonal del subespacio que generan, y comprobar el resultado.
 d) Determinar una base ortonormal del subespacio que generan, y comprobar el resultado.
 Sugerencias:  vec=Table[Table[Random[],{i,15}],{j,10}],
Det[vec.Transpose[vec]],  Y utilizar gs o Orthogonalize. 

5)  Encontrar la expresion general para la sucesión (Subscript[a, n + 1])=(Subscript[a, n])+2 (Subscript[a, n - 1

]) partiendo de (Subscript[a, 0]), (Subscript[a, 1]) genericos. "

a={{1,1},{1,0}};Clear[n,a1,a0];{z,zv}=Eigensystem[a];s=Transpose[zv];si=Inverse[s];
an=Simplify[s.DiagonalMatrix[z^n].si.{a1,a0}][[2]]

a0=0;a1=1;Simplify[an]}

a0=0;a1=1;Simplify[an]

tab=Table[Simplify[an],{n,0,20,1}]

ListPlot[tab]

a={{1,2,3},{2,3,4},{5,-6,7}};

LUDecomposition[a]

{lu,lb,lc}=LUDecomposition[a];la=Length[a];id=IdentityMatrix[la];ll=id+Table[If[j<i,lu[[i,j]],0],{i,la},{j,la}];uu=lu+id-ll;{mf[ll],mf[uu]}

{mf[ll.uu],mf[a]}

ll.uu

(* Ecuaciones Diferenciales *)

t=.;y=.;Simplify[DSolve[y''[t]+9*y[t]==Cos[3 t],y[t],t]]

Clear[t,y,w];sol=Simplify[DSolve[{y''[t]+9*y[t]==Cos[w* t]},y[t],t]]

Clear[t,y,w];sol=Simplify[DSolve[{y''[t]+9*y[t]==Cos[w* t],y[0]==0,y'[0]==0},y[t],t]]

{yy[t_,w_]}=y[t]/.sol

yy[t,w]

ListAnimate[Table[Show[{Plot[yy[t,w],{t,0,30},PlotRange->{{0,30},{-3.5,3.5}},Frame->True,FrameLabel->{StyleForm["τ",16],StyleForm["y(t)",16]},PlotStyle->Thick],Graphics[{Text[StyleForm["w=",16],{3,2.5}],Text[StyleForm[w,16],{6,2.5}]}]}],{w,0.01,6,.25}]]

w=3.01;tabt=Table[{t=tt,yy[tt,w]},{tt,0,30,0.05}];ListAnimate[Table[Show[{ListPlot[Take[tabt,10*i],Joined->True,Filling->Axis,PlotRange->{{0,30},{-3.5,3.5}},Frame->True,FrameLabel->{StyleForm["t",16],StyleForm["y(t)",16]},PlotStyle->Thick],
Graphics[{Text[StyleForm["w=",16],{3,2.5}],Text[StyleForm[w,16],{6,2.5}]}]}],{i,Length[tabt]/10}]]

w=3.01;tabt=Table[{t=tt,yy[tt,w]},{tt,0,30,0.05}];ListAnimate[Table[Show[{ListPlot[Take[tabt,10*i],Joined->True,Filling->Axis,PlotRange->{{0,30},{-3.5,3.5}},Frame->True,FrameLabel->{StyleForm["t",16],StyleForm["y(t)",16]},PlotStyle->Thick],
Graphics[{Text[StyleForm["w=",16],{3,2.5}],Text[StyleForm[w,16],{6,2.5}]}]}],{i,Length[tabt]/10}]]

w=3.01;

ListAnimate[Table[ListPlot[Table[{t=tt,yy[tt,w]},{tt,0,ttt,0.05}],Joined->True,PlotRange->{{0,30},{-3.5,3.5}},Frame->True,FrameLabel->{StyleForm["t",16],StyleForm["y(t)",16]},PlotStyle->Thick],{ttt,0.,30,.1}]]

Clear[t,y,w,ga];sol=Simplify[DSolve[{y''[t]+2*ga*y'[t]+9*y[t]==0},y[t],t]]

Clear[t,y,w,ga];sol=Simplify[DSolve[{y''[t]+2*ga*y'[t]+9*y[t]==0,y[0]==1,y'[0]==0},y[t],t]]

{yr[t_,ga_]}=y[t]/.sol;

yr[t,ga]

ListAnimate[Table[Show[{Plot[yr[t,ga],{t,0,10},PlotRange->{{0,10},{-1.5,1.5}},Frame->True,FrameLabel->{StyleForm["t",16],StyleForm["y(t)",16]},PlotStyle->Thick],Graphics[{Text[StyleForm["γ=",16],{3,1.2}],Text[StyleForm[ga,16],{3.85,1.2}]}]}],{ga,0.01,6.01,.5}]]

ga=.5;tabt=Table[{t=tt,yr[tt,ga]},{tt,0,10,0.025}];ListAnimate[Table[Show[{ListPlot[Take[tabt,10*i],Joined->True,Filling->Axis,PlotRange->{{0,10},{-1.5,1.5}},Frame->True,FrameLabel->{StyleForm["t",16],StyleForm["y(t)",16]},PlotStyle->Thick],
Graphics[{Text[StyleForm["γ=",16],{3,1.2}],Text[StyleForm[ga,16],{3.85,1.2}]}]}],{i,Length[tabt]/10}]]

(* Sistemas de ecuaciones diferenciales lineales *)

Clear[y,w,x,t];sol=Simplify[DSolve[{x'[t]==-x[t]+y[t]+Cos[w*t],y'[t]==-x[t]},{x[t],y[t]},t]]

Clear[y,w,x,t];sol=Simplify[DSolve[{x'[t]==-x[t]+y[t]+Cos[w*t],y'[t]==-x[t],y[0]==1,x[0]==0},{x[t],y[t]},t]]

Clear[xx,yy];{{xx[t_,w_]},{yy[t_,w_]}}={x[t]/.sol,y[t]/.sol}

xx[t,w]

??SingularValueDecomposition

yy[t,w]

w=.8;Plot[{xx[t,w],yy[t,w]},{t,0,100},PlotStyle->Thick]

w=3.2;ParametricPlot[{xx[t,w],yy[t,w]},{t,0,300},PlotStyle->Thick,PlotRange->{{-3,3},{-3,3}}]

Needs["Calendar`"]

DayOfWeek[{2014, 6,23}]

DayOfWeek[{810, 5,25}]

Sound[Play[Sin[2*Pi*440*t],{t,0,6}]]

Sound[{SoundNote["C"],SoundNote["G"]}]