Mathematica functions for the Rainbow Bridge

Prepared by the METRIC Project for the 
"Computing for Engineering" Course, CE109

Instructions

To set up the definitions contained in this notebook, select Evaluation -> Evaluate Notebook from the Kernel menu.

Credits and Copyrights

Version: 1.0 (02/02/98)

by Phillip Kent, METRIC Project, Imperial College, London.
 
For use in Civil Engineering course CE109 (Computing for Engineering),
Mathematica Session 3.

Based on an original idea by Professor Jon Greenman, Mathematics Department, University of Stirling.

Copyright (C) Imperial College of Science, Technology and Medicine 1998.
Portions are copyright (C) University of Stirling 1993.

Function definitions

\(\ \  (*\ Turn\ off\ warnings\ about\ spelling\ *) 

    Off[General::spell, General::spell1]


     (*\ An\ initial\ version\ of\ rainbowFun, \ calibrated\ for\ a

      	\ \ \ test\ load\ of\ 10000\ N\ in\ \(bridgeMovie.\)
*) \)\(rainbowFun[force_] := Hue[0.8*Abs[force]/18700]


     (*\ Function\ for\ palettes\ *) \)\(colorPalette[colorfunc_, {lmin_, lmax_, lstep_}] := 

      Module[{lev}, 

        \((
\ Show[
            GraphicsArray[
\ \ \ 
              Table[Graphics[{colorfunc[lev], 
                    \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
\ \ \ \ \ 
                    Polygon[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}]}, 
		
                  PlotLabel -> lev], 
\ \ {lev, lmin, lmax, lstep}]]]
)\)]

    
 (*\ Functions\ for\ 2 - bay\ bridge\ *) 
\)\(inclinationAngle = Pi/4; \  (*\ \(radians!\)\ *) 


    matrixA = {{0, Sin[inclinationAngle], 0, 0, 0, 0, 0}, 

        \ \ \ {1, Cos[inclinationAngle], 0, 0, 0, 0, 0}, 

        \ \ \ {0, 1, 1, 0, 0, 0, 0}, 

        \ \ \ {0, Cos[inclinationAngle], \(-Cos[inclinationAngle]\), \(-1\), 
          0, 0, 0}, 

        \ \ \ {1, 0, Cos[inclinationAngle], 0, \(-1\), 
          \(-Cos[inclinationAngle]\), 0}, 
\ \ \ {0, 0, 0, 0, 0, 1, 1}, 

        \ \ \ {0, 0, 0, 1, 0, Cos[inclinationAngle], 
          \(-Cos[inclinationAngle]\)}}; 


    nodalLoad[testload_, x_] := 
\ \ 
      Which[0 <= x < 1/2, 2*testload*x, 1/2 < x <= 1, 2*testload*\((1 - x)\), 
        
		\ \ True, \ 0]
\)\(bridgeForces[testload_, frames_:  20] := 

      Module[{k, x, vc}, 
\ \ 
        Table[\((
\ \ \ \ \ 
            x = \(-0.15\) + \((k - 1)\)*1.3/\((frames - 1)\); 
\ \ \ \ \ 
            vc = {nodalLoad[testload, x], 0, 0, 0, 0, 0, 0}; 
\ \ \ \ \ 
            LinearSolve[matrixA, vc])\), 
\ \ {k, \ 1, frames}]]
\)\(bridgeMovie[testload_, \ colourFunction_, \ frames_:  20] := 

      Module[{k, lg, soln, vc, x}, 

        \((
Do[
x = \(-0.15\) + \((k - 1)\)*1.3/\((frames - 1)\); 

            vc = {nodalLoad[testload, x], 0, 0, 0, 0, 0, 0}; 

            soln = LinearSolve[matrixA, vc]; 

            lg = {
\ {Text[1, {0.25, 0}, {0, \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([1]\)]], Line[{{0, 0}, {0.5, 0}}]}, 

                \ {Text[5, {0.75, 0}, {0, \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([5]\)]], Line[{{0.5, 0}, {1, 0}}]}, 

                \ {Text[3, {0.375, Sin[inclinationAngle]/4}, {0, \(+1.5\)}], 
                  
\ \ \ colourFunction[soln[\([3]\)]], 
\ \ \ 
                  Line[{{0.5, 0}, {0.25, Sin[inclinationAngle]/2}}]}, 

                \ {Text[2, {0.125, Sin[inclinationAngle]/4}, {0, \(-1.5\)}], 
                  
\ \ \ colourFunction[soln[\([2]\)]], 
\ \ \ 
                  Line[{{0, 0}, {0.25, Sin[inclinationAngle]/2}}]}, 

                \ {Text[4, {0.5, Sin[inclinationAngle]/2}, {0, \(+1\)}], 

                  \ \ \ colourFunction[soln[\([4]\)]], 
\ \ 
                  Line[{{0.75, Sin[inclinationAngle]/2}, {0.25, 
                        Sin[inclinationAngle]/2}}]}, 

                \ {Text[6, {0.625, Sin[inclinationAngle]/4}, {0, \(+1.5\)}], 
                  
\ \ \ colourFunction[soln[\([6]\)]], 
\ \ \ 
                  Line[{{0.5, 0}, {0.75, Sin[inclinationAngle]/2}}]}, 

                \ {Text[7, {0.875, Sin[inclinationAngle]/4}, {0, \(-1.5\)}], 
                  
\ \ \ colourFunction[soln[\([7]\)]], 
\ \ \ 
                  Line[{{0.75, Sin[inclinationAngle]/2}, {1, 0}}]}, 

                \ {GrayLevel[0.0], Disk[{x, .05}, .05]}, 

                \ {GrayLevel[0.5], Rectangle[{\(-.25\), \(-.1\)}, {0, 0}]}, 

                \ {GrayLevel[0.5], Rectangle[{1, \(-.1\)}, {1.25, 0}]}\ }; 

            Show[
\ Graphics[lg, Prolog -> AbsoluteThickness[4]], 
\ \ \ 
              AspectRatio -> Automatic, 
              PlotRange -> {{\(-0.3\), 1.3}, {\(-0.1\), 0.5}}], 
            
{k, 1, frames}]\ )\)]


     (*\ Functions\ for\ 4 - bay\ bridge\ *) 
\)\(matrixA2\  = \ 

      \ \ {{\(-1\)/Sqrt[2], \ 0, \ \(-1\), \ 1/Sqrt[10], \(-1\)/Sqrt[2], \ 0, 
          \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0}, 

        \ \ {\(-1\)/Sqrt[2], \ 0, \ 0, \ 3/Sqrt[10], \ 1/Sqrt[2], \ 0, \ 0, \ 
          0, \ 0, \ 0, \ 0, \ 0, \ 0}, \ \ \ 

        \ \ {0, \ 0, \ 1, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0}, 
        \ 
\ \ {0, \ \(-1\), \ 0, \ 0, \ 0, \ 1, \ 0, \ 0, \ 0, \ 0, \ 0, \ 
          0, \ 0}, \ 

        \ \ {0, \ 0, \ 0, \ \(-1\)/Sqrt[10], \ 0, \ 0, \ \(-1\), \ 
          \(-1\)/Sqrt[10], \ 0, \ 0, \ 0, \ 0, \ 0}, \ 

        \ \ {0, \ 0, \ 0, \ \(-3\)/Sqrt[10], \ 0, \ 0, \ 0, \ 3/Sqrt[10], \ 
          0, \ 0, \ 0, \ 0, \ 0}, 

        \ \ {0, \ 0, \ 0, \ 0, \ 1/Sqrt[2], \ 0, \ 1, \ 0, \ 1/Sqrt[2], \ 0, 
          \ 0, \ 0, \ 0}, 

        \ \ {0, \ 0, \ 0, \ 0, \ \(-1\)/Sqrt[2], \ \(-1\), \ 0, \ 0, \ 
          1/Sqrt[2], \ 1, \ 0, \ 0, \ 0}, \ 

        \ \ {0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 1/Sqrt[10], \ \(-1\)/Sqrt[2], 
          \ 0, \ \(-1\), \ \(-1\)/Sqrt[2], 0}, 

        \ \ {0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ \(-3\)/Sqrt[10], \ 
          \(-1\)/Sqrt[2], \ 0, \ 0, \ 1/Sqrt[2], \ 0}, 

        \ \ {0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 1, \ 0, \ 0}, 
        \ 
\ \ {0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ \(-1\), \ 0, \ 
          0, \ 1}, \ 

        \ \ {0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 
          \(-1\)/Sqrt[2], \ \(-1\)}}\ ; 


    nodalLoad2A[testload_, x_] := 
\ 
      Which[0 <= x < 1/4, \(-4\)*testload*x, 
		1/4 < x <= 1/2, 
        \(-4\)*testload*\((1/2 - x)\), True, \ 0]
\)\(nodalLoad2B[testload_, x_] := 

      Which[1/4 <= x < 1/2, \(-4\)*testload*\((x - 1/4)\), 
		
        1/2 < x <= 3/4, \(-4\)*testload*\((3/4 - x)\), True, \ 0]
\)\(nodalLoad2C[testload_, x_] := 
\ \ 
      Which[1/2 <= x < 3/4, \(-4\)*testload*\((x - 1/2)\), 
		
        3/4 < x <= 1, \(-4\)*testload*\((1 - x)\), True, \ 0]
\)\(bridgeForces2[testload_, frames_:  20] := 

      Module[{k, x, vc}, 

        Table[\((
\ \ x = \(-0.1\) + \((k - 1)\)*1.2/\((frames - 1)\); 
\ \ 
            vc = {0, 0, \(-nodalLoad2A[testload, x]\), 0, 0, 0, 

                				\ \ \ \ \(-nodalLoad2B[testload, x]\), 0, 0, 0, 
                \(-nodalLoad2C[testload, x]\), 
						0, 0}; 
\ 
            LinearSolve[matrixA2, vc])\), 
\ {k, \ 1, frames}]]
\)\(bridgeMovie2[testload_, \ colourFunction_, \ frames_:  30] := 

      Module[{k, lg, soln, vc, x}, 

        \((
Do[
x = \(-0.1\) + \((k - 1)\)*1.2/\((frames - 1)\); 

            vc = {0, 0, \(-nodalLoad2A[testload, x]\), 0, 0, 0, 
                \(-nodalLoad2B[testload, x]\), 0, 0, 
\ \ 0, 
                \(-nodalLoad2C[testload, x]\), 0, 0}; 

            soln = LinearSolve[matrixA2, vc]; 

            lg = {
\ {Text[2, {0.125, 0}, {0, \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([2]\)]], Line[{{0, 0}, {0.25, 0}}]}, 
                
\ {Text[6, {0.375, 0}, {0, \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([6]\)]], 
                  Line[{{0.25, 0}, {0.5, 0}}]}, 

                \ {Text[10, {0.625, 0}, {0, \(+1\)}], \ 
\ \ 
                  colourFunction[soln[\([10]\)]], 
                  Line[{{0.5, 0}, {0.75, 0}}]}, 

                \ {Text[13, {0.875, 0}, {0, \(+1\)}], 
\ \ 
                  colourFunction[soln[\([13]\)]], 
                  Line[{{0.75, 0}, {1.0, 0}}]}, 

                \ {Text[3, {0.25, 0.125}, {\(-1.5\), 0}], 
\ \ \ 
                  colourFunction[soln[\([3]\)]], 
                  Line[{{0.25, 0}, {0.25, 0.25}}]}, 

                \ {Text[11, {0.75, 0.125}, {\(-1.5\), 0}], 
\ \ \ 
                  colourFunction[soln[\([11]\)]], 
                  Line[{{0.75, 0}, {0.75, 0.25}}]}, 

                \ {Text[7, {0.5, 0.1667}, {\(-1.5\), 0}], 
\ \ \ 
                  colourFunction[soln[\([7]\)]], 
                  Line[{{0.5, 0}, {0.5, 0.333}}]}, 

                \ {Text[1, {0.125, 0.125}, {\(-1\), \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([1]\)]], 
                  Line[{{0, 0}, {0.25, 0.25}}]}, 

                \ {Text[12, {0.875, 0.125}, {\(-1.65\), 0}], 
\ \ \ 
                  colourFunction[soln[\([12]\)]], 
                  Line[{{0.75, 0.25}, {1.0, 0}}]}, 

                \ {Text[5, {0.375, 0.125}, {\(+1\), \(-1.5\)}], 
\ \ \ 
                  colourFunction[soln[\([5]\)]], 
                  Line[{{0.25, 0.25}, {0.5, 0}}]}, 

                \ {Text[9, {0.625, 0.125}, {\(-1\), \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([9]\)]], 
                  Line[{{0.5, 0}, {0.75, 0.25}}]}, 

                \ {Text[4, {0.375, 0.29}, {\(-1\), \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([4]\)]], 
                  Line[{{0.25, 0.25}, {0.5, 0.333}}]}, 

                \ {Text[8, {0.625, 0.29}, {\(+1\), \(+1\)}], 
\ \ \ 
                  colourFunction[soln[\([8]\)]], 
                  Line[{{0.5, 0.333}, {0.75, 0.25}}]}, 

                \ {GrayLevel[0.0], Disk[{x, .04}, .04]}, 

                \ {GrayLevel[0.5], Rectangle[{\(-.2\), \(-.1\)}, {0, 0}]}, 

                \ {GrayLevel[0.5], Rectangle[{1, \(-.1\)}, {1.2, 0}]}\ }; 

            Show[
\ Graphics[lg, Prolog -> AbsoluteThickness[4]], 
\ \ \ 
              AspectRatio -> Automatic, 
              PlotRange -> {{\(-0.2\), 1.2}, {\(-0.1\), 0.37}}], 
            
{k, 1, frames}]\ )\)]

\ \ 
     (*\ Turn\ back\ on\ warnings\ about\ spelling\ *) \)On[General::spell, General::spell1]