Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
309 lines (228 sloc) 6.47 KB
title: Perl 6 and the Real World
subtitle: Physical Modelling with Perl 6
author: Moritz Lenz <moritz@faui2k3.org>
affiliation: Max Planck Institute for the Science of Light
------------
= Perl 6 and the Real World - Structure
* What is a model? When is it a good model?
* A simple model
* Math: derivatives
* Free fall, spring
* Resonance
= What is a Model?
* physics = striving to understand (parts of) the world
* the world is too complicated
* models are descriptions that focus on one aspect
* so Model = Simplification
= Example Model
:raw
<center>
<img src="s-swing.jpg" />
</center>
= Example Model
:raw
<center>
<img src="s-swing-model.png" />
</center>
= Model takes into account
* gravity
* inertia
* initial motion
* connection to anchor point
= Model neglects
* colors
* exact shapes
* size of object
* friction
= Is it a good model?
* it's a good model if it can answer a question for us
* examples "how fast is the object?", "What is the swinging period?",
"Does the distance to the anchor point matter?"
* accuracy of the answer important
* every model needs input data. Is that available?
* extensibilty
= Another model: free falling
:raw
<center>
<img src="s-free-fall-model.png" />
</center>
= Free falling: Solved in Perl 6
:perl6
use Math::Model;
my $m = Math::Model.new(
derivatives => {
velocity => 'height',
acceleration => 'velocity',
},
variables => {
acceleration => { $:gravity }, # m / s**2
gravity => { -9.81 }, # m / s**2
},
# ...
= Free falling: Solved in Perl 6
:perl6
# ...
initials => {
height => 50, # m
velocity => 0, # m/s
},
captures => ('height', 'velocity'),
);
$m.integrate(:from(0), :to(4.2), :min-resolution(0.2));
$m.render-svg('free-fall.svg', :title('Free falling'));
= Model result
:raw
<center>
<img src="s-free-fall.png" />
</center>
= The model in detail
:perl6
use Math::Model;
my $m = Math::Model.new(
derivatives => {
velocity => 'height',
acceleration => 'velocity',
},
= Derivative: slope of another quantity
:raw
<center>
<img src="s-derivative.png" />
</center>
= Common derivatives in Mechanics
:text
Derivative Of
velocity position
angular velocity angle
acceleration velocity
power energy
force momentum
(= mass * velocity)
= Common derivatives
:text
current charge
birth rate population
- mortality rate
profit funds
= Using derivatives
* with Math::Model, you only need to know the derivatives,
note the values derived from
* you need an initial value for the derived quantity
* (Ordinary Differential Equation, which Math::Model integrates for you)
= Rest of the model
:perl6
variables => {
acceleration => { $:gravity }, # m / s**2
gravity => { -9.81 }, # m / s**2
},
initials => {
height => 50, # m
velocity => 0, # m/s
},
captures => ('height', 'velocity'),
);
$m.integrate(:from(0), :to(4.2), :min-resolution(0.2));
$m.render-svg('free-fall.svg', :title('Free falling'));
= Perl 6 stuff
* `$:height` is a named parameter
* `Math::Model` introspects code blocks for arguments
* calculates dependencies => execution order
* RungeKutta integration
= Extending the model - Spring, damping
:raw
<center>
<img src="s-spring-model.png" />
</center>
= Spring, gravity, damping: source code
:perl6
# ...
variables => {
acceleration => { $:gravity + $:spring + $:damping },
gravity => { -9.81 },
spring => { - 2 * $:height },
damping => { - 0.2 * $:velocity },
},
# ...
= Spring, gravity, damping: results
:raw
<center>
<img src="spring-damping-result.png" />
</center>
= Further extensions
* Let's add an external, driving force
* Example: motor, coupled through a second spring
= External driving force: Code
:perl6
sub MAIN($freq) {
my $m = Math::Model.new(
# ...
variables => {
acceleration => { $:gravity + $:spring
+ $:damping + $:ext_force },
gravity => { -9.81 },
spring => { - 2 * $:height },
damping => { - 0.2 * $:velocity },
ext_force => { sin(2 * pi * $:time * $freq) },
},
# ...
);
my %h = $m.integrate(:from(0), :to(70), :min-resolution(5));
$m.render-svg("spring-freq-$freq.svg",
:title("Spring with damping, external force at $freq"));
= Driving force: low frequency
:raw
<center>
<img src="spring-freq-0.04.png" />
</center>
= Driving force: higher frequency
:raw
<center>
<img src="spring-freq-0.06.png" />
</center>
= Driving force: higher frequency
:raw
<center>
<img src="spring-freq-0.2.png" />
</center>
= Driving force: higher frequency
:raw
<center>
<img src="spring-freq-0.22.png" />
</center>
= Driving force: higher frequency
:raw
<center>
<img src="spring-freq-0.26.png" />
</center>
= Driving force: higher frequency
:raw
<center>
<img src="spring-freq-0.48.png" />
</center>
= External driving force: Observations
* amplitude low for small frequencies
* amplitude high for driving freq = eigen freq
* amplitude goes to zero for very high frequencies
= Amplitude vs. Frequency
:raw
<center>
<img src="resonance.png" height="440" />
</center>
= Resonance controls ...
* tune of music instruments
* light absorption, thus color of objects
* heat transport in solids (phonons are lattice resonances)
* everything else :-)
= String theories
* some physicists say that particles are just resonances
* the things that move are called "strings"
* think of it what you want :-)
= Limits of Math::Model
* some fields of physics require other mathematical techniques
* many need partial differential equations
* no quantum mechanics
* no fluid dynamics
= Summary
* physical models: simplifcation to essentials
* `Math::Model` integrates models for you
* oscillator: initial motion + force in opposite direction
* resonance if driving frequency is close to eigen frequency
Something went wrong with that request. Please try again.