(***************Função morrinho*************)
f[z_]:=Exp[-z^2]
Plot[f[z],{z,-4,4},PlotRange->{-1,1}]

(***************Colisão de morrinhos*************)
v=1;
g1[x_,t_]:=f[x-v t]
g2[x_,t_]:=f[-x-v t]
gp[x_,t_]:=g1[x,t]+g2[x,t]
gm[x_,t_]:=g1[x,t]-g2[x,t]
vgm[x_,t_]:=-v f'[x-v t]+v f'[-x-v t]
Animate[Plot[gp[x,t],{x,-10,10},PlotRange->{-1,2},AspectRatio->1/10],{t,-5,5},AnimationRunning->False]
Animate[Plot[gm[x,t],{x,-10,10},PlotRange->{-1,2},AspectRatio->1/10],{t,-5,5},AnimationRunning->False]
Animate[Show[Plot[gm[x,t],{x,-10,10},PlotRange->{-2,2},AspectRatio->1/10],Table[Graphics[{Red,Line[{{x,gm[x,t]},{x,gm[x,t]+vgm[x,t]}}]}],{x,-10,10,0.25}],PlotRange->{-2,2},AspectRatio->1/10],{t,-5,5},AnimationRunning->False]

(************Reflexão e transmissão************)
v1=1.;
v2=0.5;
gin[x_,t_]:=f[x-v1 t]
gr[x_,t_]:=(v2-v1)/(v2+v1)gin[-x,t]
gt[x_,t_]:=2v2/(v2+v1)gin[v1 x/v2,t]
yd[t_]:=gt[0,t]

y1=3;
y2=2y1;
ratio=1/3;
xmin=-10;
xmax=10;
ymin=-1;
ymax=1+y2;
Animate[Show[Plot[gt[x,t],{x,0,10},PlotRange->{{xmin,xmax},{ymin,ymax}},AspectRatio->ratio,Axes->False],Plot[gin[x,t]+gr[x,t],{x,-10,0},PlotRange->{{xmin,xmax},{ymin,ymax}},AspectRatio->ratio,Axes->False,PlotStyle->RGBColor[1,0,0]],Plot[y2+gin[x,t]+gr[x,t],{x,-10,0},PlotRange->{{xmin,xmax},{ymin,ymax}},AspectRatio->ratio,Axes->False,PlotStyle->RGBColor[1,0,0]],Plot[y2+gin[x,t]+gr[x,t],{x,0,10},PlotRange->{{xmin,xmax},{ymin,ymax}},AspectRatio->ratio,Axes->False,PlotStyle->{Dashed,RGBColor[1,0,0]}],Plot[y1+gt[x,t],{x,0,10},PlotRange->{{xmin,xmax},{ymin,ymax}},AspectRatio->ratio,Axes->False],Plot[y1+gt[x,t],{x,-10,0},PlotRange->{{xmin,xmax},{ymin,ymax}},AspectRatio->ratio,Axes->False,PlotStyle->Dashed],Graphics[Disk[{0,gt[0,t]},0.1]]],{t,-5,5},AnimationRunning->False]

(****Interferência de ondas harmônicas de mesma frequência******)
A1=1;
v=1;
Animate[Show[Plot[ A1 Cos[k(x-v t)]+A2 Cos[k(x-sinal*v t)+fase],{x,-10,10},PlotStyle->Black],Plot[{ 5+A1 Cos[k(x-v t)],5+A2 Cos[k(x-sinal*v t)+fase]},{x,-10,10}],Plot[{0,5},{x,-10,10},PlotStyle->{{Dashed,RGBColor[0,1,0]}}],Axes->False,PlotRange->{-3,7},AspectRatio->1/3],{t,-10,10},{A2,0,2,0.5},{k,0,4Pi},{fase,0,2Pi,Pi/5},{sinal,1,-1,-2},AnimationRunning->False]

(****Interferência de ondas harmônicas de frequências distintas******)
A1=1;
k1=2Pi;
v1=0;
Animate[Show[Plot[ A1 Cos[k1(x-v1 t)]+A2 Cos[k2(x-sinal*v2 t)],{x,0,20},PlotStyle->Black],Plot[{ 5+A1 Cos[k1(x-v1 t)],5+A2 Cos[k2(x-sinal*v2 t)]},{x,0,20}],Plot[{0,5},{x,0,20},PlotStyle->{{Dashed,RGBColor[0,1,0]}}],Axes->False,PlotRange->{-3,7},AspectRatio->1/3],{t,0,100},{A2,0,2,0.5},{k2,k1,k1+1},{sinal,1,-1,-2},{v2,v1,v1+1},AnimationRunning->False]

f=440;
Play[Sin[2Pi*f*t],{t,0,3}]

df=1;
Play[Sin[2Pi*f*t]+Sin[2Pi*(f+df)t],{t,0,3}]

v=1;
k1=1;
k2=1.1;
t=0;
g=Plot[{Cos[k1(x-v t)]+ Cos[k2(x-v t)],2Cos[(k1-k2)x/2],-2Cos[(k1-k2)x/2],4+Cos[k1(x-v t)],4+Cos[k2(x-v t)]},{x,-10,80},PlotStyle->{Black,{Black,Dashed},{Black,Dashed},Red,Blue},Axes->False]
Clear[v,k1,k2,t]

Export[NotebookDirectory[]<>"batimento.png",g,"PNG",ImageResolution->200,Background->None]

(*Som: deslocalmento, densidade e pressão*)
u[x_,t_,A_,l_]:=A Cos[2Pi(x-t)/l]
dP[x_,t_,A_,l_]:=A Sin[2Pi(x-t)/l]
dr[x_,t_,A_,l_]:=A Sin[2Pi(x-t)/l]

r=0.1;
A=0.1;
l=2;
Animate[Show[Table[Graphics[{Circle[{x,0},r],Disk[{x+u[x,t,A,l],-1},r]}],{x,-10,10,0.3}],Plot[{u[x,t,A,l]-2,dP[x,t,A,l]-3,dr[x,t,A,l]-4},{x,-10,10},Axes->False],Plot[{-2,-3,-4},{x,-10,10},Axes->False,PlotStyle->Dashed],PlotRange-> {{-11,11},{-4.5,0.5}}],{t,-5,5},AnimationRunning->False]

r=0.05;
g=Show[Table[Graphics[{Dashed,Line[{{x,-0.1},{x,-4}}]}],{x,0,10,0.5}],Table[Graphics[{Circle[{x,0},r],Disk[{x+1.5u[x,0,A,l],-1},r]}],{x,0,10,0.25}],Plot[{2u[x,0,A,l]-2,2dP[x,0,A,l]-3,2dr[x,0,A,l]-4},{x,0,10},Axes->False],Plot[{-2,-3,-4},{x,0,10},Axes->False,PlotStyle->Dashed],PlotRange-> {{0,5},{-4.5,0.5}}]

Export[NotebookDirectory[]<>"som.png",g,"PNG",ImageResolution->200,Background->None]

(*Doppler*)
xf[x0f_,vf_,t_]:=x0f+vf*t
xr[x0r_,vr_,t_]:=x0r+vr*t

vf=0.8;
vr=0.3;
tmax=10;
Animate[Show[{Graphics[{Disk[{xf[0,vf,t],0},0.2],Table[If[t>n/f,Circle[{xf[0,vf,n/f],0},t-n/f]],{n,0,tmax f}]}],Graphics[{Red,Disk[{xr[-5,vr,t],0},0.2]}],Graphics[{Blue,Disk[{xr[5,vr,t],0},0.2]}]},PlotRange->{{-10,10},{-5,5}}],{t,0,tmax},{f,1,5,1},AnimationRunning->False]

(*Difracao*)

field[x_,x0_,y_,y0_,t_]:=Cos[2Pi(Sqrt[(x-x0)^2+(y-y0)^2]-t)]

anima=Animate[ContourPlot[field[x,-5,y,-5,t]+field[x,5,y,-5,t],{x,-10,10},{y,-5,5},PlotRange->{-2,2},PlotLegends->Automatic,ContourStyle->None,AspectRatio->1/2],{t,0,1},AnimationRunning->False]

Export[NotebookDirectory[]<>"anima3.swf",anima,"SWF"]

Export[NotebookDirectory[]<>"2sources.gif",g,"AnimationRepetitions"->∞]

Export[NotebookDirectory[]<>"1source.gif",g1source,"AnimationRepetitions"->∞]

g1source=Table[ContourPlot[field[x,0,y,0,t],{x,-10,10},{y,-10,10},PlotRange->{-1,1},PlotLegends->Automatic,ContourStyle->None,AspectRatio->1,PlotPoints->40],{t,0,1,0.05}];

g=Table[ContourPlot[field[x,-5,y,-5,t]+field[x,5,y,-5,t],{x,-10,10},{y,-5,5},PlotRange->{-2,2},PlotLegends->Automatic,ContourStyle->None,AspectRatio->1/2,PlotPoints->40],{t,0,1,0.05}];

t=0;
ContourPlot[field[x,-5,y,-5,t]+field[x,5,y,-5,t],{x,-10,10},{y,-5,5},PlotRange->{-2,2},PlotLegends->Automatic,ContourStyle->None,AspectRatio->1/2,PlotPoints->20]
Clear[t]

field2[x_,x0_,y_,y0_,t_]:=Cos[2Pi(Sqrt[(x-x0)^2+(y-y0)^2]-t)]/Sqrt[Sqrt[(x-x0)^2+(y-y0)^2]]

x01=-1.6;
y01=0;
x02=-x01;
y02=y01;
y=100;
g=Plot[NIntegrate[(field2[x,x01,y,y01,t]+field2[x,x02,y,y02,t])^2,{t,0,1}],{x,-350,350},Axes->False,PlotRange->All,PlotStyle->Thick]
Clear[y,t]

Export[NotebookDirectory[]<>"difraction.png",g,"PNG",ImageResolution->100,Background->None]

t1=0.14;
t2=0.282;
Tan[t1]
Tan[t2]

Series[Sqrt[1+(t+x/4)^2],{x,0,4}]

z1=Tan[t1];
z2=Tan[t2];
FullSimplify[Solve[Sqrt[1+(z1+e)^2]-Sqrt[1+(z1-e)^2]==(Sqrt[1+(z2+e)^2]-Sqrt[1+(z2-e)^2])/2,e]]

e=0.23773;
2(Sqrt[1+(z1+e)^2]-Sqrt[1+(z1-e)^2])
Clear[e]

g=Plot[{Sin[x]Cos[0],Sin[x]Cos[Pi/4],Sin[x]Cos[Pi/2],Sin[x]Cos[3Pi/4],Sin[x]Cos[Pi]},{x,-1,4Pi+1}(*,PlotStyle->{Black,{Black,Dashed},{Black,Dashed},Red,Blue}*),Axes->False,AspectRatio->1/4]

Export[NotebookDirectory[]<>"onda-estacionaria.png",g,"PNG",ImageResolution->200,Background->None]