Engineering Education | Things to Try

Make edits and run any piece of code by clicking inside the code and pressing
+
.

Solve a differential equation

Model the motion of a pendulum in Cartesian coordinates. Derive the governing equations using Newton’s second law of motion,
m
′
′
x
(t)∑
F
x
and
m
′
′
y
(t)∑
F
y
, with a force diagram:
Run
Run
Define the equation, set up the algebraic constraint and initial conditions:
Run
In[]:=
deqns={x''[t]λ[t]x[t],y''[t]λ[t]y[t]-9.81};​​aeqns={
2
x[t]
+
2
y[t]

2
1
};​​ics={x[0]1,y'[0]1};
Use
NDSolve
to solve the differential equation:
Run
In[]:=
sol1=NDSolve[{deqns,aeqns,ics},{x,y,λ},{t,0,5},Method{"IndexReduction"True}]
Out[]=
xInterpolatingFunction
Domain: {{0.,5.}}
Output: scalar
,yInterpolatingFunction
Domain: {{0.,5.}}
Output: scalar
,λInterpolatingFunction
Domain: {{0.,5.}}
Output: scalar

Visualize the displacement in both x and y direction about time:
Run
In[]:=
Plot[Evaluate[{x[t],y[t]}/.sol1],{t,0,5}]
Out[]=

Interactive demonstrations for mechanical engineering

Simulating vehicle suspension with a simplified quarter-car model:
Run
In[]:=
ResourceData["Demonstration: Simulating Vehicle Suspension with a Simplified Quarter-Car Model"]
Out[]=

Interactive demonstrations for electrical engineering

A power source supplies a voltage that is some combination of sine waves, represented by a phasor diagram. For sin(x), the phasor diagram would be a unit vector rotating about the origin. A more complex circuit gives a combination of these, representing the changes in electromagnetic quantities as circuit parameters are varied.
Run
In[]:=
ResourceData["Demonstration: Circuit Phasor Diagram for Transformers"]
Out[]=

Signal processing

FIR filters applied to an audio object:
In[]:=
a=ExampleData[{"Audio","Apollo11ReturnSafely"},"Audio"];​​lp=LowpassFilter[a,
800
Hz
,101];​​hp=HighpassFilter[a,
1600
Hz
,101];​​bs=BandstopFilter[a,
800
Hz
,
1600
Hz
,91];
Plot the periodogram of the original and processed signals:
In[]:=
Periodogram[{a,bs,lp,hp},2000,PlotRange{{0,3000},Automatic},FrameTrue,ImageSizeMedium,PlotLegends{"Original","Bandstop","Lowpass","Highpass"}]
Out[]=
Original
Bandstop
Lowpass
Highpass

System design and control theory

Define the equations of motion for a pendulum on a wheel (like a Segway):
Run
In[]:=
diffeqs={-lmSin[θ[t]]
2
′
θ
[t]
-(m+M)
′′
x
[t]+lmCos[θ[t]]
′′
θ
[t]F[t],​​-gSin[θ[t]]-Cos[θ[t]]
′′
x
[t]+l
′′
θ
[t]0}
Out[]=
{-lmSin[θ[t]]
2
′
θ
[t]
-(m+M)
′′
x
[t]+lmCos[θ[t]]
′′
θ
[t]F[t],-gSin[θ[t]]-Cos[θ[t]]
′′
x
[t]+l
′′
θ
[t]0}
Create a dynamic model by specifying states, inputs, outputs and parameter values:
Run
In[]:=
system=NonlinearStateSpaceModel[diffeqs,{θ[t],x[t]},F[t],{θ[t],x[t]},t]/.{M->10,m->80,l->1,g->9.8}
Out[]=
θ[t]
x.
1
[t]
x.
1
[t]
-
882.Sin[θ[t]]
-90+80
2
Cos[θ[t]]
+
Cos[θ[t]]F[t]+80Sin[θ[t]]
2
x.
1
[t]

-90+80
2
Cos[θ[t]]
x[t]
x.
2
[t]
x.
2
[t]
-
784.Cos[θ[t]]Sin[θ[t]]
-90+80
2
Cos[θ[t]]
+
F[t]+80Sin[θ[t]]
2
x.
1
[t]
-90+80
2
Cos[θ[t]]
θ[t]
x[t]
Choose poles in the left-half plane for the closed-loop system:
Run
In[]:=
p={-1+2I,-1-2I,-0.35+0.35I,-0.35-0.35I}