481 - Hermite

435 days ago by Professor481

# This cell in Sage mode var('u') H0 = (1-u)^2*(1+2*u) H1 = (1-u)^2*u H2 = (u-1)*u^2 H3 = (3-2*u)*u^2 G = plot(H0,(u,0,1),color='black')+plot(H1,(u,0,1),color='red')+plot(H2,(u,0,1),color='green')+plot(H3,(u,0,1),color='blue') show(G,aspect_ratio=1) 
       

The rest of this is in octave mode

function y = H0(u) y = (1-u) .^2 .* (1+2*u) end function y = H1(u) y = (1-u) .^2 .*u end function y = H2(u) y = (u-1) .* u .^2 end function y = H3(u) y = (3-2 .*u) .* u .^2 end n = 3 x = [-1 2 3 7] y = [5 4 2 3] m = [1 -2 1 -1] for k = 2:n+1 xx = x(k-1):0.5:x(k); delx = x(k)-x(k-1); yy = H0( (xx-x(k-1))/(x(k)-x(k-1)) )*y(k-1) + H1( (xx-x(k-1))/(x(k)-x(k-1)) )*m(k-1)*delx + H2( (xx-x(k-1))/(x(k)-x(k-1)) )*m(k)*delx + H3( (xx-x(k-1))/(x(k)-x(k-1)) )*y(k); plot(xx,yy) hold on end 
       
n = 3
x =

 -1 2 3 7

y =

 5 4 2 3

m =

 1 -2 1 -1

y =

 1 0.925926 0.740741 0.5 0.259259 0.0740741 0

y =

 0 0.115741 0.148148 0.125 0.0740741 0.0231481 0

y =

 -0 -0.0231481 -0.0740741 -0.125 -0.148148 -0.115741 0

y =

 0 0.0740741 0.259259 0.5 0.740741 0.925926 1

y =

 1 0.5 0

y =

 0 0.125 0

y =

 -0 -0.125 0

y =

 0 0.5 1

y =

 1 0.957031 0.84375 0.683594 0.5 0.316406 0.15625 0.0429688 0

y =

 0 0.0957031 0.140625 0.146484 0.125 0.0878906 0.046875 0.0136719 0

y =

 -0 -0.0136719 -0.046875 -0.0878906 -0.125 -0.146484 -0.140625
-0.0957031 0

y =

 0 0.0429688 0.15625 0.316406 0.5 0.683594 0.84375 0.957031 1

                                                                        

 6
|-----------------------------------------------------------------------\
|   
   |             +              +             +              +          
|   
   |            *********                                               
|   
   |         ***         *                                              
|   
   |       **             *                                             
|   
 5 |-+    *                *                                            
+-|   
   |                        *                                           
|   
   |                         *                                          
|   
   |                          *                                         
|   
   |                           *                                        
|   
 4 |-+                          #                                       
+-|   
   |                            #                                       
|   
   |                             #                   $$$$$$$$$$$        
|   
   |                             #                 $$           $$$     
|   
   |                              #             $$$                $    
|   
 3 |-+                            #           $$                    $   
+-|   
   |                               #         $                          
|   
   |                               ##       $                           
|   
   |                                 ##   $$                            
|   
   |             +              +       $$    +              +          
|   
 2
|-----------------------------------------------------------------------\
|   
  -2             0              2             4              6          
8   
                                                                        
n = 3
x =

 -1 2 3 7

y =

 5 4 2 3

m =

 1 -2 1 -1

y =

 1 0.925926 0.740741 0.5 0.259259 0.0740741 0

y =

 0 0.115741 0.148148 0.125 0.0740741 0.0231481 0

y =

 -0 -0.0231481 -0.0740741 -0.125 -0.148148 -0.115741 0

y =

 0 0.0740741 0.259259 0.5 0.740741 0.925926 1

y =

 1 0.5 0

y =

 0 0.125 0

y =

 -0 -0.125 0

y =

 0 0.5 1

y =

 1 0.957031 0.84375 0.683594 0.5 0.316406 0.15625 0.0429688 0

y =

 0 0.0957031 0.140625 0.146484 0.125 0.0878906 0.046875 0.0136719 0

y =

 -0 -0.0136719 -0.046875 -0.0878906 -0.125 -0.146484 -0.140625 -0.0957031 0

y =

 0 0.0429688 0.15625 0.316406 0.5 0.683594 0.84375 0.957031 1

                                                                               
 6 |-----------------------------------------------------------------------|   
   |             +              +             +              +             |   
   |            *********                                                  |   
   |         ***         *                                                 |   
   |       **             *                                                |   
 5 |-+    *                *                                             +-|   
   |                        *                                              |   
   |                         *                                             |   
   |                          *                                            |   
   |                           *                                           |   
 4 |-+                          #                                        +-|   
   |                            #                                          |   
   |                             #                   $$$$$$$$$$$           |   
   |                             #                 $$           $$$        |   
   |                              #             $$$                $       |   
 3 |-+                            #           $$                    $    +-|   
   |                               #         $                             |   
   |                               ##       $                              |   
   |                                 ##   $$                               |   
   |             +              +       $$    +              +             |   
 2 |-----------------------------------------------------------------------|   
  -2             0              2             4              6             8