(* TUTORIAL (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,300]

N[E,1000]

3!

100!

N[100!]

1000!

N[1000!]

Plot[Sin[x],{x,-2 Pi,2 Pi}]

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

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],{x,0,4}]

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

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

pn[x,1]

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]

h[x_]:=Sin[x^2/Tan[Sqrt[1+x^4/Exp[x]]]];

h[x]

p=Series[h[x],{x,0,2}]

p=Normal[p]

Plot[{h[x],p},{x,-1,1},PlotStyle->Thick]

h'[x]

FindRoot[h'[x]==0,{x,-0.5}]

Plot[{h[x],h'[x]},{x,-1,1},PlotStyle->Thick]

hh[x_]=Exp[-x^2/10]*Cos[x]

Series[hh[x],{x,0,10}]

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

pn[x,4]

pn[x,20]

Plot[hh[x],{x,-10,10},PlotStyle->Thick,PlotRange->{{-8,8},{-2,2}}]

p4=pn[x,4];p2=pn[x,2];p20=pn[x,20];Plot[{hh[x],p2,p4,p20},{x,-10,10},PlotStyle->Thick,PlotRange->{{-8,8},{-2,2}}]

(* Series *)

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

N[a]

N[Sum[1/n^2,{n,10}]]

N[Sum[1/n^2,{n,100}]]

N[Sum[1/n^2,{n,10000}]]

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

ListPlot[{Table[{m,a},{m,100}],Table[{m,sm[m]},{m,100}]},PlotRange->{{0,100},{0.5,1.8}}]

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

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

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

Zeta[2]

Plot[Zeta[p],{p,1,10},PlotRange->{{0,10},{0,5}},PlotStyle->Thick]

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

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}};

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]

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

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

a[[1]]

a//mf

a[[1,All]]

a[[All,1]]

{z,zv}=Eigensystem[a];s=Transpose[zv];si=Inverse[s];

z

s//mf

{Tr[a],Tr[z]}

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

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

si.a.s//mf//Chop

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 *)

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]

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}};

(* 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["t",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]

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"]}]