Examples

This loads the package.
In[1]:=
Click for copyable input
In this section we define all parts for a simple gear mechanism. We start with defining a Wheel. It contains the geometry and a method graph to draw itself.
In[2]:=
Click for copyable input
Next, we combine a set of Wheels. The graphics method maps over the Wheels and asks them for their graphics information.
In[3]:=
Click for copyable input
We now create a specific gear box.
In[4]:=
Click for copyable input
Out[4]=
Out[5]=
This box can transmit a given angular velocity.
In[6]:=
Click for copyable input
Out[6]=
Finally, we look at a graphical representation. Please evaluate the next input to make the graphics active.
In[7]:=
Click for copyable input
Out[7]=
This loads the package.
In[1]:=
Click for copyable input
In this example we look at the benefit of easy creation of similar, but not identical objects. We will model the deceleration of a chain of cars when the first car slows down. The position of car number j is zj[t] and its velocity zj'[t]. The first car has number one. Because all cars are in a chain, zj[t]<zj-1[t].
In order to avoid crashes of cars, the braking force increases with an increasing relative speed of cars and decreases with an increasing distance of cars. The simplest model uses proportionality, here with constant A.
Click for copyable input
This force must be equal to the inertial one.
Click for copyable input
A reaction time of nonzero can also be modeled.
Click for copyable input
Let us model a Car as a class. The possibility to access "previous" values by means of the history field will be implemented below in a derived class.
In[2]:=
Click for copyable input
The access to the history is done in a CompiledFunction in order to be faster. It could be included in the class as a class method.
In[3]:=
Click for copyable input
Now, we add the caching of a Car's history.
In[4]:=
Click for copyable input
Again we outsource the access to the history field for convenience to keep the class small.
In[5]:=
Click for copyable input
A bunch of cars is easily created, each with the same weight, break and reaction time. Later, we will change this,
In[6]:=
Click for copyable input
The behavior of the first car is arbitrarily assumed : starting with constant speed of 30m/s, then a sine term is added. All cars start with constant spacing and with the same velocity as the first car.
In[8]:=
Click for copyable input
Out[11]=
We are ready for the simulation.
The Cars' movement s controlled by the first car.
In[14]:=
Click for copyable input
Out[15]=
Now, we assume that the driver of the second ca reacts slower. Please observe that the example does not detect a car crash in Mathematica version 5.
This loads the package.
In[1]:=
Click for copyable input
In this example we will model spherical lenses in two dimensions. We focus on a simple model, calculation speed is not an issue here. First, we derive a function to calculate ray-surface intersections.
We calculate the intersection of a ray starting at {rx, ry} with angle and a plane as well as a circle of radius R, both centered at {cx, cy}.
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
In order to reduce calculation time during the simulation, we optimize the intersection calculation and plug it into a function. The handling of the messages ::"indet", Divide::"infy" and Power::"infy" is necessary, because the optimization does not take care of branches in the solution of Reduce that are not evaluated due to failed conditions within And.
In[4]:=
Click for copyable input
The numeric values to check the ray-surface intersection also cover some special cases.
In[5]:=
Click for copyable input
In the plot,the found intersections are marked with red dots, while the red lines are generated from the calculated angular coordinates of the circle at the intersection points. Rays are drawn in black with their starting point marked with a dot. The circle and the plane are drawn in blue.
In[8]:=
Click for copyable input
Out[10]=
The direction of the new ray is generated by refraction.
In[11]:=
Click for copyable input
Out[11]=
In order to get physically correct lenses, the simulation will prevent that two surfaces intersect. The check for intersection is obtained analogous to the surface-ray intersections above. Because we are only interested, if there is an intersection, we pick one set of values for C[1] and C[2]. The test is restricted to lenses centered about the x axis.
In[12]:=
Click for copyable input
Out[12]=
In[13]:=
Click for copyable input
A short numeric test is executed.
In[14]:=
Click for copyable input
In[15]:=
Click for copyable input
Out[18]=
Out[19]=
A ray contains geometry information on the travelled path as well as methods to create and terminate ray segments. The interface is introduced to later separate rays and optical elements.
In[20]:=
Click for copyable input
In[21]:=
Click for copyable input
For convenience, we define a ray source.
In[22]:=
Click for copyable input
The model's main part are the surfaces. They collect all surface-specific data and provide a method to refract rays. The interface is introduced to later separate rays and optical elements.
In[23]:=
Click for copyable input
In[24]:=
Click for copyable input
A lens in this model is composed of two spherical surfaces. In order to keep the model simple, we only will vary the radii and the thickness of the lens, while its position is kept fixed.
In[25]:=
Click for copyable input
Optical System
Finally, rays and optical elements are combined in an optical system. The screen should be illuminated by parallel rays with a large diameter. Additionally, no rays should be lost.The beamQualities method tests how good the criteria are fulfilled.
In[26]:=
Click for copyable input
The optical system to be considered is composed of two lenses and a screen.
In[27]:=
Click for copyable input
A first trace is executed.
In[28]:=
Click for copyable input
Out[28]=
Here is the tracing's result.
In[29]:=
Click for copyable input
Out[29]=
In[30]:=
Click for copyable input
Out[30]=
We now execute a simple genetic optimization. First, a set of 5 optical systems is created and traced.
In[31]:=
Click for copyable input
In[32]:=
Click for copyable input
Out[32]=
In[34]:=
Click for copyable input
Out[34]//TableForm=
In[35]:=
Click for copyable input
Out[35]=
From every generation, we drop the systems with the worst qualities and create a clone of those with the best qualities. The qualities are taken into account independently.
In[36]:=
Click for copyable input
Out[36]=
Here is a sketch of the obtained qualities.
In[37]:=
Click for copyable input
Out[37]=

The last optimization step shows the "best" systems found. Please observe that the system is far from being good. The example was kept simple and should only show how modeling can be done.
In[38]:=
Click for copyable input
Out[38]=
In[39]:=
Click for copyable input
Out[39]=
This loads the package.
In[1]:=
Click for copyable input
In this example a bottom up design of analog computer circuits is shown. Every part of the model is a block with connections to other blocks.After defining specific elements from these blocks and connecting them, the blocks yield a set of differential equations that describe the system behavior.
The basic element contains all general functionality to define elements, connect them and obtain equations. Elements may have one output and several inputs.
In[2]:=
Click for copyable input
For a visual check, the block gets functionality to draw itself.
In[3]:=
Click for copyable input
Here are a few specific elements.
In[4]:=
Click for copyable input
In[5]:=
Click for copyable input
In[6]:=
Click for copyable input
Next, we create a simple system.
In[7]:=
Click for copyable input
In[10]:=
Click for copyable input
In[13]:=
Click for copyable input
Out[13]=
The equations that describe the system are automatically generated.
In[14]:=
Click for copyable input
Out[14]=
We simplify by means of the algebraic part.
In[15]:=
Click for copyable input
Out[15]=
Out[16]=
We are now ready to solve the equations.
In[17]:=
Click for copyable input
Out[17]=
Out[18]=
Out[19]=
This system can easily be expanded to incorporate damping.
In[20]:=
Click for copyable input
In[22]:=
Click for copyable input
In[26]:=
Click for copyable input
Out[26]=
In[27]:=
Click for copyable input
Out[27]=
Out[29]=
In[30]:=
Click for copyable input
Out[30]=
Out[31]=
Out[32]=