MEC-E1005 Workshop 2024

Least-squares method

Least-squares fit

(*measured x-y data*)
data={{0,0},{1.0,1.0},{2.0,2.0},{3.0,3.0},{4.0,3.5},{6.5,5.0},{2.5,2.5},{5.0,4.0}};

{xi,yi}=Transpose[data];

P={1,x,x^2,x^3};
KK=Sum[Outer[Times,P,P],{x,xi}];
FF=yi.Table[P,{x,xi}];
y=Simplify[P.Inverse[KK].FF]

Show[Plot[y,{x,Min[xi],Max[xi]},FrameLabel->{"x","y"},Frame->True],
ListPlot[data,PlotStyle->Black]]

Least-squares approximation

(*function*)
y = Coth[x]+Sin[x];
Ω=Line[{{1},{4}}];

(*project*)
P={1,x};
KK=NIntegrate[Outer[Times,P,P],{x}∈Ω];
FF=NIntegrate[P y,{x}∈Ω];
yy=Simplify[P.Inverse[KK].FF]

(*compare*)
Plot[{y,yy},{x}∈Ω,Frame->True,FrameLabel->{"x","y/yy"},PlotStyle->{Black,Blue}]

Fourier transform

Discrete Fourier transform

y=10Sin[2 π 10 t]+5Sin[2 π 35.6 t]-16 Sin[2 π 50 t];

(*sample y*) 
T=2; f=1000;
ti = Table[i*1.,{i,0,T,1/f}];
yi = Table[y,{t,ti}];

(*transform to frequency domain*)
yf=Fourier[yi];

(*frequency-amplitude plot*)
gr=MapIndexed[{(First[#2]-1)/T,#1}&,Abs[yf]];
Plot[y,{t,0,1/2},Frame->True,FrameLabel->{"t[s]",None}]
ListPlot[gr,Joined->True,PlotRange->{{0,100},All},Frame->True,FrameLabel->{"f[1/s]",None}]

Sound analysis

(*generate sound in some way*)
T=3;
(*aud=AudioGenerator[Sin[2*Pi 255 #]&,T]*)
aud=Audio[Sound[SoundNote["C4",T]]]
(*aud=AudioCapture[MaxDuration->T]*)
(*SetDirectory[NotebookDirectory[]]; aud=Audio["Bowl14.wav"]*)

(*analyse sound*)
dat=AudioData[aud][[1]];
T=Length[dat]/(SampleRate /. Options[aud])*1.;
α=Fourier[dat];

(*amplitude as function of frequency*)
fα=MapIndexed[{(First[#2]-1)/T,#1}&,Abs[α]];
ListPlot[fα,Joined->True,PlotRange->{{0,1200},All},Frame->True,FrameLabel->{"f [1/s]",None}]

Displacement FEA

SetDirectory[NotebookDirectory[]];
Get["FemDefs.m"];

Beam bending

(*problem desciption tables*)
ele={
{BEAM,{{Ε,G},{A, Iyy,Izz},{0,0,fz}},Line[{1,2}]},
{BEAM,{{Ε,G},{A, Iyy,Izz},{0,0,fz}},Line[{2,3}]},
{FORCE,{-F,0,0},Point[{3}]}};
fun={
{{0,0,0},{0,0,0},{0,0,0}},
{{L/2,0,0},{uX[2],0,uZ[2]},{0,θY[2],0}},
{{L,0,0},{uX[3],0,0},{0,θY[3],0}}};

FORMATTED[{ele,fun}]

(*solve*)
sol=SOLVE[{ele,fun}]

Plate bending

val={L->5,H->5, t->0.01,ν->0.3,Ε->210 (10^9),ρ-> 8000,g->9.81,fz-> ρ  g t};

(*geometry*)
Ω=DiscretizeRegion[Rectangle[{0,0},{L,H}] /.val,MaxCellMeasure->0.25];
nod=MeshCells[Ω,2];
crd=MeshCoordinates[Ω];
Σ=MeshCells[BoundaryMesh[Ω],0] /. Point[a_]->a;

Show[Ω,Axes->True,AxesLabel->{X,Y}];

(*problem desciption tables*)
ele=Map[{PLATE,{{Ε,ν},{t},{0,0,fz}},#}&,nod] //.val;
fun=MapIndexed[{Append[#1,0],{0,0,uZ[First[#2]]},
{θX[First[#2]],θY[First[#2]],0}}&,crd];
fun[[Σ,2]]={0,0,0};

FORMATTED[{ele,fun}];

(*solve*)
sol=SOLVE[{ele,fun}];
SHOW3D[{DISP,50},{ele,fun}/.sol]