⍝ Function limit 'trajectory':

    {2|⍵:1+3×⍵ ⋄ ⍵÷2}traj 7                     ⍝ Trajectory of osc function
7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

⍝ This operator gives the next approximation in a Newton-Raphson iteration:

    nr←{                    ⍝ Newton-Raphson.
        ⍺←⎕CT               ⍝ default increment.
        y ∆y←⍺⍺¨⍵+0 ⍺       ⍝ f(⍵), f(⍵+∆)
        ⍵+(⍺×y)÷y-∆y        ⍝ next estimate.
    }

:If ⎕FR=1287
        2∘○ nr traj 1.5         ⍝ Root of Cos(x) near 1.5.
    1.5 1.570914844 1.570796327 1.570796327
        1e¯3∘(2∘○ nr)traj 1.5   ⍝ Same again but with an explicit increment.
    1.5 1.570912342 1.570796327 1.570796327 1.570796327 1.570796327
:Else
        2∘○ nr traj 1.5         ⍝ Root of Cos(x) near 1.5.
    1.5 1.570990983 1.570796171 1.570796327 1.570796327 1.570796327
        1e¯3∘(2∘○ nr)traj 1.5   ⍝ Same again but with an explicit increment.
    1.5 1.570912342 1.570796327 1.570796327
:EndIf

    ' *'[⎕io+↑≠\traj 32⍴1]          ⍝ Sierpinski triangle.
********************************
* * * * * * * * * * * * * * * * 
**  **  **  **  **  **  **  **  
*   *   *   *   *   *   *   *   
****    ****    ****    ****    
* *     * *     * *     * *     
**      **      **      **      
*       *       *       *       
********        ********        
* * * *         * * * *         
**  **          **  **          
*   *           *   *           
****            ****            
* *             * *             
**              **              
*               *               
****************                
* * * * * * * *                 
**  **  **  **                  
*   *   *   *                   
****    ****                    
* *     * *                     
**      **                      
*       *                       
********                        
* * * *                         
**  **                          
*   *                           
****                            
* *                             
**                              
*                               

⍝ Alternative coding:

    traj2←{
        ¯1∘↓∘(,∘⊂∘⍺⍺∘⊃∘⌽⍨⍣(∊⍨∘⊂∘⊃∘⌽⍨)∘⊂)⍵
    }

    {2|⍵:1+3×⍵ ⋄ ⍵÷2}traj2 7                ⍝ Trajectory of osc function.
7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

⍝∇ traj

Back to: code

Back to: Workspaces