next up previous contents
Next: Lebenslauf Up: Mathematica-Programme Previous: MATHEMATICA-Programm zur Maximumsuche

MATHEMATICA-Programm zur Maximumsuche durch Potenzierung und Fit

. MAXIMIERUNG DURCH POTENZIERUNG UND FIT

                                                                                                                                                                    
Unprotect[Times]                                                                                                                                                                    
0. _ := 0                                                                                                                                                                           
Protect[Times]                                                                                                                                                                      
                                                                                                                                                                                    
MaxFitWeightPower = 2                                                                                                                                                               
                                                                                                                                                                                    
MaxFit1[fp_,{x_,a_,b_}] := Block[{A,B,dA,a4,a3,a2,a1,a0,fpn,alpha,beta,gamma},                                                                                                      
                            fpn = fp^MaxFitWeightPower;                                                                                                                             
                            Array[A,{3,3}];                                                                                                                                         
                            Array[B,{3}];                                                                                                                                           
                            Print["Calculating a4"];                                                                                                                                
                            a4 = Integrate[Expand[fpn x^4],{x,a,b}];                                                                                                                
                            Print["Calculating a3"];                                                                                                                                
                            a3 = Integrate[Expand[fpn x^3],{x,a,b}];                                                                                                                
                            Print["Calculating a2"];                                                                                                                                
                            a2 = Integrate[Expand[fpn x^2],{x,a,b}];                                                                                                                
                            Print["Calculating a1"];                                                                                                                                
                            a1 = Integrate[Expand[fpn x],{x,a,b}];                                                                                                                  
                            Print["Calculating a0"];                                                                                                                                
                            a0 = Integrate[Expand[fpn], {x,a,b}];                                                                                                                   
                            A = {{a4,a3,a2},{a3,a2,a1},{a2,a1,a0}};                                                                                                                 
                            dA = Det[A];                                                                                                                                            
                            Print[StringForm["Determinant=``",dA]];                                                                                                                 
                            B = {Print["Calculating b2"];                                                                                                                           
                                 Integrate[Expand[fpn fp x^2],{x,a,b}],                                                                                                             
                                 Print["Calculating b1"];                                                                                                                           
                                 Integrate[Expand[fpn fp x],{x,a,b}],                                                                                                               
                                 Print["Calculating b0"];                                                                                                                           
                                 Integrate[Expand[fpn fp],{x,a,b}]};                                                                                                                
                            alpha = Det[{B,{a3,a2,a1},{a2,a1,a0}}]/dA;                                                                                                              
                            beta  = Det[{{a4,a3,a2},B,{a2,a1,a0}}]/dA;                                                                                                              
                            gamma = Det[{{a4,a3,a2},{a3,a2,a1},B}]/dA;                                                                                                              
                           (* Plot[{fp,alpha x^2+beta x+gamma},{x,a,b}]; *)                                                                                                         
                            {alpha,beta,gamma}                                                                                                                                      
                           ]                                                                                                                                                        
                                                                                                                                                                                    
MaxFind1::usage = "MaxFind1[f,{x,a,b},mfp] finds the absoulute Maximum of a                                                                                                         
 non-negative                                                                                                                                                                       
                   function f[x] in the interval a<x<b.                                                                                                                             
                   mfp is the used power, can be omitted, default is 8."                                                                                                            
MaxFind1[f_,{x_,a_,b_},mfp_:8] :=                                                                                                                                                   
                           Block[{k,d,w},                                                                                                                                           
                            Print[StringForm["Interval ``,                                                                                                                          
 MaxFitPower=``",{a,b},mfp]];                                                                                                                                                       
                            MaxFitResult = MaxFit1[f^mfp,{x,a,b}];                                                                                                                  
                            ka=MaxFitResult[[1]];                                                                                                                                   
                            kb=MaxFitResult[[2]];                                                                                                                                   
                            kc=MaxFitResult[[3]];                                                                                                                                   
                            k =kb/(-2 ka);                                                                                                                                          
                            d =kb^2 - 4 ka kc;                                                                                                                                      
                            fehlb = Sqrt[d]/(2 ka);                                                                                                                                 
                            k                                                                                                                                                       
                           ]                                                                                                                                                        
                                                                                                                                                                                    
MaxFit2[fp_,{x1_,a1_,b1_},{x2_,a2_,b2_}] :=                                                                                                                                         
         Block[{A,B,a40,a22,a04,a30,a03,a21,a12,a20,a02,a11,a10,a01,a00,fpn,r,                                                                                                      
                c20,c02,c10,c01,c00},                                                                                                                                               
                fpn = fp^MaxFitWeightPower;                                                                                                                                         
                Array[A,{5,5}];                                                                                                                                                     
                Array[B,{5}];                                                                                                                                                       
                a40 = Integrate[Expand[fpn x1^4],{x1,a1,b1},{x2,a2,b2}];                                                                                                            
                a04 = Integrate[Expand[fpn x2^4],{x1,a1,b1},{x2,a2,b2}];                                                                                                            
                a22 = Integrate[Expand[fpn x1^2 x2^2],{x1,a1,b1},{x2,a2,b2}];                                                                                                       
                a30 = Integrate[Expand[fpn x1^3],{x1,a1,b1},{x2,a2,b2}];                                                                                                            
                a03 = Integrate[Expand[fpn x2^3],{x1,a1,b1},{x2,a2,b2}];                                                                                                            
                a21 = Integrate[Expand[fpn x1^2 x2],{x1,a1,b1},{x2,a2,b2}];                                                                                                         
                a12 = Integrate[Expand[fpn x1 x2^2],{x1,a1,b1},{x2,a2,b2}];                                                                                                         
                a20 = Integrate[Expand[fpn x1^2],{x1,a1,b1},{x2,a2,b2}];                                                                                                            
                a02 = Integrate[Expand[fpn x2^2],{x1,a1,b1},{x2,a2,b2}];                                                                                                            
                a11 = Integrate[Expand[fpn x1 x2],{x1,a1,b1},{x2,a2,b2}];                                                                                                           
                a10 = Integrate[Expand[fpn x1],{x1,a1,b1},{x2,a2,b2}];                                                                                                              
                a01 = Integrate[Expand[fpn x2],{x1,a1,b1},{x2,a2,b2}];                                                                                                              
                a00 = Integrate[Expand[fpn],{x1,a1,b1},{x2,a2,b2}];                                                                                                                 
                                                                                                                                                                                    
                A = {{a40,a22,a30,a21,a20},                                                                                                                                         
                     {a22,a04,a12,a03,a02},                                                                                                                                         
                     {a30,a12,a20,a11,a10},                                                                                                                                         
                     {a21,a03,a11,a02,a01},                                                                                                                                         
                     {a20,a02,a10,a01,a00}};                                                                                                                                        
                Print[TableForm[A]];                                                                                                                                                
                Print[StringForm["Determinant=``",Det[A]]];                                                                                                                         
                B = {Integrate[Expand[fpn fp x1^2],{x1,a1,b1},{x2,a2,b2}],                                                                                                          
                     Integrate[Expand[fpn fp x2^2],{x1,a1,b1},{x2,a2,b2}],                                                                                                          
                     Integrate[Expand[fpn fp x1],{x1,a1,b1},{x2,a2,b2}],                                                                                                            
                     Integrate[Expand[fpn fp x2],{x1,a1,b1},{x2,a2,b2}],                                                                                                            
                     Integrate[Expand[fpn fp],{x1,a1,b1},{x2,a2,b2}]};                                                                                                              
                r = Solve[A.{c20,c02,c10,c01,c00}==B];                                                                                                                              
                Flatten[{c20,c02,c10,c01,c00}/.r]                                                                                                                                   
               ]                                                                                                                                                                    
                                                                                                                                                                                    
MaxFind2[f_,{x1_,a1_,b1_},{x2_,a2_,b2_},mfp_:8] :=                                                                                                                                  
          Block[{k},                                                                                                                                                                
                 MaxFitResult = MaxFit2[f^mfp,{x1,a1,b1},{x2,a2,b2}];                                                                                                               
                 k20=MaxFitResult[[1]];                                                                                                                                             
                 k02=MaxFitResult[[2]];                                                                                                                                             
                 k10=MaxFitResult[[3]];                                                                                                                                             
                 k01=MaxFitResult[[4]];                                                                                                                                             
                 k00=MaxFitResult[[5]];                                                                                                                                             
                 {-k10/(2 k20), -k01/(2 k02)}                                                                                                                                       
               ]                                                                                                                                                                    
                                                                                                                                                                                    
machmfp = 10                                                                                                                                                                        
                                                                                                                                                                                    
test = 10 - (x1-0.2)^2 - (x2-0.4)^2                                                                                                                                                 
                                                                                                                                                                                    
mach2 := MaxFind2[test,{x1,-1,1},{x2,-1,1},machmfp]                                                                                                                                 
                                                                                                                                                                                    
fit2 := k20 x1^2 + k02 x2^2 + k10 x1 + k01 x2 + k00                                                                                                                                 
                                                                                                                                                                                    
fit1 := ka x^2 + kb x + kc



Werner Eberl
Fri Apr 14 00:36:50 MET DST 1995