Ignore:
Timestamp:
Feb 3, 2014 3:36:30 PM (9 years ago)
Author:
srkline
Message:

Two changes to existing model functions:

1) For the 2-yukawa model: Added conditions to enforce Z1>Z2. If this condition is not met, then a valid-looking (but incorrect) S(q) may be returned. These conditions were identified and satisfied within Yun's original Matalb code but were not transferred to the Igor code or XOP. These conditions are enforced within the Igor code before sending to either the XOP or local Igor code.

2) For the Teubner-Strey model: The coefficients have been re-written in terms of the two length scales and a proper absolute scaling. The Macro to calculate the length scales now also reports the amphiphilicity factor.

3) The help file entries for both of these functions have been appropriately updated.

Location:
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2010/Two_Yukawa_v40.ipf

    r824 r931  
    2626// conversion to Igor from the c-code was not terribly painful, and very useful for debugging. 
    2727// 
     28// 
     29// JAN 2014 SRK - added code to enforce Z1 > Z2. If this condition is not met, then the calculation will 
     30//  return a solution, but it will be incorrect (the result will look like a valid structure factor, but be incorrect) 
     31//  This condition is necessary due to the asymmetric treatment of these parameters in the mathematics of the calculation 
     32//  by Yun Liu. A lower limit constraint has been added (automatically) so that the condition will be met while fitting 
     33//  - without this constraint, parameter "flips" will confound the optimization. This LoLim wave only been added to the  
     34//    calculation of S(Q), not any combination PS functions. 
     35// --- This, unfortunately means that all of the "_Sq" macros *MAY* need to be updated to reflect this constraint 
     36//     so it will actually be enforced during fitting. I think I'll note this in the manual, and see if the fitting can 
     37//     handle this. If it can't. I'll instruct users to add a LoLim to the Z1, and this should take care of this issue 
     38//     Otherwise- I may just introduce more problems by programmatically enforcing "hidden" constraints, and have a lot more 
     39//     code to maintain if the constraints are not quite correct in all situations. 
     40// 
     41// JAN 2014 - added code to bypass the condition Z1 == Z2, which is also diallowed in Yun's code. 
     42// -- code to prevent K1 == 0 or K2 == 0 was previously in place. 
     43// These conditions are all specified in Yun's "Appendix B" for the "TYSQ21 Matlab Package" 
    2844// 
    2945// 
     
    122138        Label left "Structure Factor" 
    123139        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2) 
     140 
     141        // make a constraint wave appropriate for the Z1 > Z2 condition for fitting 
     142        // setting the lower bound on Z1 (> Z2) is sufficient to meet this condition 
     143        // and check the box on the panel so that constraints are used 
     144        Duplicate/O parameters_2yuk Lolim_2yuk 
     145        LoLim_2yuk = "" 
     146        LoLim_2yuk[3] = "K5" 
     147         
     148        CheckBox check_2,win=wrapperPanel,value= 1 
     149 
    124150         
    125151        AddModelToStrings("TwoYukawa","coef_2yuk","parameters_2yuk","2yuk") 
     
    129155 
    130156//AAO version 
     157// 
    131158Function TwoYukawa(cw,yw,xw) : FitFunc 
    132159        Wave cw,yw,xw 
    133160 
     161// make sure that none of the values are too close to zero 
     162// make them very small instead 
    134163        if(abs(cw[2]) < 0.001) 
    135164                cw[2] = 0.001 
     
    143172        if(abs(cw[5]) < 0.001) 
    144173                cw[5] = 0.001 
     174        endif    
     175 
     176        if(cw[3] == cw[5])              // Z1 == Z2 not allowed, this may not be enough of a correction 
     177                cw[3] *= 1.001 
     178        endif    
     179 
     180// JAN 2014 -- SRK 
     181// if I do a swap on cw, then the values on the table "flip" and is very un-natural 
     182// - but it may be OK. Alternatively, I could create a tmp wave to pass through into the calculation. 
     183 
     184         
     185// then make sure that Z1 > Z2 is true 
     186// swap 1 and 2 if needed 
     187        Variable tmp 
     188        if(cw[5] > cw[3]) 
     189        //swap the K values 
     190                tmp = cw[2] 
     191                cw[2] = cw[4] 
     192                cw[4] = tmp 
     193        // then the Z values     
     194                tmp = cw[3] 
     195                cw[3] = cw[5] 
     196                cw[5] = tmp 
    145197        endif    
    146198         
     
    639691        t5 = (-8.*m32*m44*Z1 + m32*m44*(-8. + 3.*Z1)*Z2 + (3.*m32*m44 - 4.*(m14*(m32 + 3.*m41 - 2.*m42) + m44)*Z1)*pow(Z2,2) +  m34*(Z1 + Z2)*t3 + 2.*m31*(Z1 + Z2)*t4 - 4.*m14*m32*pow(Z2,3)) 
    640692                         
    641         TY_qc123 = (2.*phi*pow(Z2,-2)*(9.*t1 + 4.*(-2.*m44*Z1 + m34*(Z1 + Z2))*pow(m11,2)*pow(Z2,2) - 3.*m24*t2 - 6.*m11*t5)*pow(Z1 + Z2,-1))/3.; 
     693        TY_qc123 = (2.*phi*pow(Z2,-2)*(9.*t1 + 4.*(-2.*m44*Z1 + m34*(Z1 + Z2))*pow(m11,2)*pow(Z2,2) - 3.*m24*t2 - 6.*m11*t5)*pow(Z1 + Z2,-1))/3. 
    642694         
    643695         
     
    647699        t4 = (4.*(3.*m31 - 2.*m32)*m44 + Z1*(-4.*m31*m44 + 3.*m32*m44 - 2.*(m14*(-6.*m31 + 4.*m32 + 3.*m41 - 2.*m42) + m44)*Z1) + m34*(m42*(8. - 3.*Z1) + 4.*m41*(-3. + Z1) + 4.*pow(Z1,2))) 
    648700         
    649         TY_qc132 = (-2.*phi*pow(Z1,-2)*(9.*t1 + 4.*(-2.*m34*Z2 + m44*(Z1 + Z2))*pow(m11,2)*pow(Z1,2) +  3.*m24*t2 + 6.*m11*(Z1*t3 + Z2*t4))*pow(Z1 + Z2,-1))/3.; 
     701        TY_qc132 = (-2.*phi*pow(Z1,-2)*(9.*t1 + 4.*(-2.*m34*Z2 + m44*(Z1 + Z2))*pow(m11,2)*pow(Z1,2) +  3.*m24*t2 + 6.*m11*(Z1*t3 + Z2*t4))*pow(Z1 + Z2,-1))/3. 
    650702                 
    651703                 
     
    714766        t2 = (exp(2*Z1)*t1 - TY_qc112*(Z1 + Z2)*pow(Z1,2) + 2*(Z1 + Z2)*exp(Z1)*(TY_qa12 + (TY_qa12 + TY_qb12)*Z1 + TY_qc112*pow(Z1,2))) 
    715767                   
    716         TY_A12 = 6*phi*TY_qc112*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*TY_qc212*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + exp(Z2)*t2)*pow(Z1 + Z2,-1); 
     768        TY_A12 = 6*phi*TY_qc112*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*TY_qc212*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + exp(Z2)*t2)*pow(Z1 + Z2,-1) 
    717769         
    718770         
     
    721773        t3 = (2*(TY_qa12*TY_qc121 + TY_qa21*TY_qc112*(1 + Z1) + Z1*t2)*(Z1 + Z2)*exp(Z1) + exp(2*Z1)*t1 - 2*TY_qc112*TY_qc121*(Z1 + Z2)*pow(Z1,2)) 
    722774                   
    723         TY_A21 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*(TY_qc121*TY_qc212 + TY_qc112*TY_qc221)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) +  exp(Z2)*t3)*pow(Z1 + Z2,-1); 
     775        TY_A21 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*(TY_qc121*TY_qc212 + TY_qc112*TY_qc221)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) +  exp(Z2)*t3)*pow(Z1 + Z2,-1) 
    724776         
    725777         
     
    728780        t3 = (12*phi*(TY_qa12*TY_qc122 + TY_qa22*TY_qc112*(1 + Z1) + Z1*t1)*(Z1 + Z2)*exp(Z1) - 2*phi*TY_qc112*TY_qc122*(Z1 + Z2)*pow(Z1,2) + exp(2*Z1)*(6*phi*t2 + TY_q22*TY_qc112*(Z1 + Z2)*pow(Z1,3))) 
    729781                   
    730         TY_A22 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(12*phi*(TY_qc122*TY_qc212 + TY_qc112*TY_qc222)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) +  exp(Z2)*t3)*pow(Z1 + Z2,-1); 
     782        TY_A22 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(12*phi*(TY_qc122*TY_qc212 + TY_qc112*TY_qc222)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) +  exp(Z2)*t3)*pow(Z1 + Z2,-1) 
    731783         
    732784         
     
    735787        t3 = (2*Z1*(TY_qb23*TY_qc112*(-1 + Z1)*(Z1 + Z2) + TY_qb12*TY_qc123*(-1 + Z1)*(Z1 + Z2) - Z1*t1) + TY_qa23*TY_qc112*(Z1 + Z2)*(-2 + pow(Z1,2)) +  TY_qa12*TY_qc123*(Z1 + Z2)*(-2 + pow(Z1,2))) 
    736788         
    737         TY_A23 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*(TY_qc123*TY_qc212 + TY_qc112*TY_qc223)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + exp(Z2)*(2*t2*(Z1 + Z2)*exp(Z1) +  exp(2*Z1)*t3 - 2*TY_qc112*TY_qc123*(Z1 + Z2)*pow(Z1,2)))*pow(Z1 + Z2,-1); 
     789        TY_A23 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*(TY_qc123*TY_qc212 + TY_qc112*TY_qc223)*exp(Z1)*(-Z2 + (Z1 + Z2)*exp(Z1))*pow(Z1,2) + exp(Z2)*(2*t2*(Z1 + Z2)*exp(Z1) +  exp(2*Z1)*t3 - 2*TY_qc112*TY_qc123*(Z1 + Z2)*pow(Z1,2)))*pow(Z1 + Z2,-1) 
    738790         
    739791         
     
    749801        t10 = (12*phi*(TY_qa23*TY_qc121 + TY_qa22*TY_qc122 + TY_qa21*TY_qc123 + TY_qa12*TY_qc132 + TY_qa32*TY_qc112*(1 + Z1) + Z1*t1)*(Z1 + Z2)*exp(Z1 + Z2) - 12*phi*t2*Z2*exp(Z1)*pow(Z1,2) + 12*phi*t3*(Z1 + Z2)*exp(2*Z1)*pow(Z1,2) - 6*phi*(Z1 + Z2)*exp(Z2)*t4*pow(Z1,2) + exp(2*Z1 + Z2)*(TY_q22*t5 + 6*phi*t9))   
    750802                   
    751         TY_A32 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*t10*pow(Z1 + Z2,-1); 
     803        TY_A32 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*t10*pow(Z1 + Z2,-1) 
    752804         
    753805         
     
    757809        t4 = (-2*(TY_qa32*TY_qc121 + TY_qa21*(TY_q22 + TY_qc132)) - 2*(TY_qb32*TY_qc121 + TY_qb21*(TY_q22 + TY_qc132))*Z1 + (TY_qa32*TY_qc121 + 2*TY_qb32*TY_qc121 + TY_qa21*TY_qc132 + 2*TY_qb21*TY_qc132 - 2*TY_qc121*TY_qc132 + TY_q22*(TY_qa21 + 2*TY_qb21 - 2*TY_qc121 - 2*TY_qc221) - 2*TY_qc132*TY_qc221 - 2*TY_qc121*TY_qc232)*pow(Z1,2)) 
    758810         
    759         TY_A41 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*exp(Z1)*t1*pow(Z1,2) + exp(Z2)*(2*t2*(Z1 + Z2)*exp(Z1) - 2*TY_qc121*TY_qc132*(Z1 + Z2)*pow(Z1,2) + exp(2*Z1)*(Z2*t3 + Z1*t4)))*pow(Z1 + Z2,-1); 
     811        TY_A41 = 6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*exp(Z1)*t1*pow(Z1,2) + exp(Z2)*(2*t2*(Z1 + Z2)*exp(Z1) - 2*TY_qc121*TY_qc132*(Z1 + Z2)*pow(Z1,2) + exp(2*Z1)*(Z2*t3 + Z1*t4)))*pow(Z1 + Z2,-1) 
    760812         
    761813         
     
    767819        t6 = (12*phi*(TY_qa22*TY_qc132 + TY_qa32*TY_qc122*(1 + Z1) + Z1*t1)*(Z1 + Z2)*exp(Z1 + Z2) - 12*phi*t2*Z2*exp(Z1)*pow(Z1,2) + 12*phi*t3*(Z1 + Z2)*exp(2*Z1)*pow(Z1,2) - 12*phi*TY_qc122*TY_qc132*(Z1 + Z2)*exp(Z2)*pow(Z1,2) + exp(2*Z1 + Z2)*t5) 
    768820                 
    769         TY_A42 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*t6*pow(Z1 + Z2,-1); 
     821        TY_A42 = exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*t6*pow(Z1 + Z2,-1) 
    770822         
    771823         
     
    775827        t4 = (2*TY_qa32*TY_qc123 + 2*TY_qa23*(TY_q22 + TY_qc132) + 2*(TY_qb32*TY_qc123 + TY_qb23*(TY_q22 + TY_qc132))*Z1 + (-(TY_qa32*TY_qc123) - (TY_qa23 + 2*TY_qb23)*TY_qc132 + TY_q22*(-TY_qa23 + 2*(-TY_qb23 + TY_qc123 + TY_qc132 + TY_qc223)) + 2*(-(TY_qb32*TY_qc123) + TY_qc132*(TY_qc123 + TY_qc223) + TY_qc123*TY_qc232) + 2*pow(TY_q22,2))*pow(Z1,2)) 
    776828         
    777         TY_A43 = -6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*exp(Z1)*t1*pow(Z1,2) + exp(Z2)*(-2*t2*(Z1 + Z2)*exp(Z1) + 2*TY_qc123*TY_qc132*(Z1 + Z2)*pow(Z1,2) + exp(2*Z1)*(Z2*t3 + Z1*t4)))*pow(Z1 + Z2,-1); 
     829        TY_A43 = -6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*exp(Z1)*t1*pow(Z1,2) + exp(Z2)*(-2*t2*(Z1 + Z2)*exp(Z1) + 2*TY_qc123*TY_qc132*(Z1 + Z2)*pow(Z1,2) + exp(2*Z1)*(Z2*t3 + Z1*t4)))*pow(Z1 + Z2,-1) 
    778830         
    779831         
     
    782834        t3 = ((TY_q22 + TY_qc132)*exp(2*Z1)*t2 + (Z1 + Z2)*pow(TY_qc132,2)*pow(Z1,2) - 2*TY_qc132*(Z1 + Z2)*exp(Z1)*(TY_qa32 + (TY_qa32 + TY_qb32)*Z1 + (TY_q22 + TY_qc132)*pow(Z1,2))) 
    783835         
    784         TY_A52 = -6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*TY_qc232*exp(Z1)*t1*pow(Z1,2) + exp(Z2)*t3)*pow(Z1 + Z2,-1); 
     836        TY_A52 = -6*phi*exp(-2*Z1 - Z2)*pow(TY_q22,-2)*pow(Z1,-3)*(2*TY_qc232*exp(Z1)*t1*pow(Z1,2) + exp(Z2)*t3)*pow(Z1 + Z2,-1) 
    785837         
    786838         
     
    834886        t4 = (exp(Z1)*(2*Z2*t3 + TY_qa21*TY_qc212*(Z1 + Z2)*(-2 + pow(Z2,2)) + TY_qa12*TY_qc221*(Z1 + Z2)*(-2 + pow(Z2,2))) + 2*(TY_qc121*TY_qc212 + TY_qc112*TY_qc221)*(Z1 + Z2)*pow(Z2,2)) 
    835887         
    836         TY_B12 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc212*TY_qc221*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*((Z1 + Z2)*t1*exp(Z1) + t2*Z1*pow(Z2,2)) + exp(2*Z2)*t4)*pow(Z1 + Z2,-1); 
     888        TY_B12 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc212*TY_qc221*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*((Z1 + Z2)*t1*exp(Z1) + t2*Z1*pow(Z2,2)) + exp(2*Z2)*t4)*pow(Z1 + Z2,-1) 
    837889         
    838890         
     
    846898        t6 = (TY_q22*(TY_qa12 + 2*TY_qb12 - 2*TY_qc112 - 2*TY_qc212) + TY_qc212*(TY_qa23 + 2*TY_qb23 - 2*TY_qc123 - 2*TY_qc223) + (TY_qa12 + 2*TY_qb12 - 2*TY_qc112)*TY_qc223) 
    847899         
    848         TY_B14 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc212*TY_qc223*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*t1 +  exp(2*Z2)*(2*t2*(Z1 + Z2)*pow(Z2,2) + exp(Z1)*(-2*t3*Z1 - 2*t4*Z2 + t5*pow(Z2,2) + t6*pow(Z2,3))))*pow(Z1 + Z2,-1); 
     900        TY_B14 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc212*TY_qc223*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*t1 +  exp(2*Z2)*(2*t2*(Z1 + Z2)*pow(Z2,2) + exp(Z1)*(-2*t3*Z1 - 2*t4*Z2 + t5*pow(Z2,2) + t6*pow(Z2,3))))*pow(Z1 + Z2,-1) 
    849901         
    850902         
     
    854906        t3 = (-(TY_qc121*Z1*pow(Z2,2)) + (Z1 + Z2)*exp(Z1)*(TY_qa21 + (TY_qa21 + TY_qb21)*Z2 + TY_qc221*pow(Z2,2))) 
    855907         
    856         TY_B21 = 6*phi*TY_qc221*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-t1 +  exp(2*Z2)*t2 + 2*exp(Z2)*t3)*pow(Z1 + Z2,-1); 
     908        TY_B21 = 6*phi*TY_qc221*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-t1 +  exp(2*Z2)*t2 + 2*exp(Z2)*t3)*pow(Z1 + Z2,-1) 
    857909         
    858910         
     
    864916        t5 = (6*phi*(2*Z2*t4 + TY_qa22*TY_qc221*(Z1 + Z2)*(-2 + pow(Z2,2)) + TY_qa21*TY_qc222*(Z1 + Z2)*(-2 + pow(Z2,2))) + TY_q22*TY_qc221*(Z1 + Z2)*pow(Z2,3)) 
    865917         
    866         TY_B22 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-12*phi*TY_qc221*TY_qc222*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 12*phi*exp(Z2)*t2 + exp(2*Z2)*(12*phi*t3*(Z1 + Z2)*pow(Z2,2) +  exp(Z1)*t5))*pow(Z1 + Z2,-1); 
     918        TY_B22 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-12*phi*TY_qc221*TY_qc222*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 12*phi*exp(Z2)*t2 + exp(2*Z2)*(12*phi*t3*(Z1 + Z2)*pow(Z2,2) +  exp(Z1)*t5))*pow(Z1 + Z2,-1) 
    867919         
    868920         
     
    885937        t15 = (-6*phi*(Z1 + Z2)*exp(Z1)*t1*pow(Z2,2) +  12*phi*exp(Z2)*t13 +  exp(2*Z2)*(12*phi*t4*(Z1 + Z2)*pow(Z2,2) +  exp(Z1)*(TY_q22*TY_qc222*(Z1 + Z2)*pow(Z2,3) - 6*phi*(2*t5*Z1 + 2*t6*Z2 - (-2*t7 +  t8*Z1)*pow(Z2,2) - t14*pow(Z2,3))))) 
    886938         
    887         TY_B23 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*t15*pow(Z1 + Z2,-1); 
     939        TY_B23 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*t15*pow(Z1 + Z2,-1) 
    888940         
    889941         
     
    895947        t6 = (12*phi*(Z1 + Z2)*t1*exp(Z1 + Z2) - 12*phi*TY_qc222*TY_qc223*(Z1 + Z2)*exp(Z1)*pow(Z2,2) - 12*phi*t2*Z1*exp(Z2)*pow(Z2,2) + 12*phi*t3*(Z1 + Z2)*exp(2*Z2)*pow(Z2,2) + exp(Z1 + 2*Z2)*t5) 
    896948                 
    897         TY_B24 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*t6*pow(Z1 + Z2,-1); 
     949        TY_B24 = exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*t6*pow(Z1 + Z2,-1) 
    898950 
    899951         
     
    901953        t2 = ((Z1 + Z2)*exp(Z1)*pow(TY_qc223,2)*pow(Z2,2) + (TY_q22 + TY_qc223)*exp(2*Z2)*t1 + 2*TY_qc223*exp(Z2)*(TY_qc123*Z1*pow(Z2,2) - (Z1 + Z2)*exp(Z1)*(TY_qa23 + (TY_qa23 + TY_qb23)*Z2 + (TY_q22 + TY_qc223)*pow(Z2,2)))) 
    902954         
    903         TY_B25 = -6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*t2*pow(Z1 + Z2,-1); 
     955        TY_B25 = -6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*t2*pow(Z1 + Z2,-1) 
    904956         
    905957         
     
    909961        t4 = (exp(Z1)*(2*Z2*t3 + TY_qa32*TY_qc221*(Z1 + Z2)*(-2 + pow(Z2,2)) + TY_qa21*TY_qc232*(Z1 + Z2)*(-2 + pow(Z2,2))) + 2*(TY_qc132*TY_qc221 + TY_qc121*TY_qc232)*(Z1 + Z2)*pow(Z2,2))   
    910962         
    911         TY_B32 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc221*TY_qc232*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*((Z1 + Z2)*t1*exp(Z1) + t2*Z1*pow(Z2,2)) + exp(2*Z2)*t4)*pow(Z1 + Z2,-1); 
     963        TY_B32 = 6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(-2*TY_qc221*TY_qc232*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*((Z1 + Z2)*t1*exp(Z1) + t2*Z1*pow(Z2,2)) + exp(2*Z2)*t4)*pow(Z1 + Z2,-1) 
    912964         
    913965 
     
    919971        t6 = (2*t3*Z1 + 2*t4*Z2 - t5*pow(Z2,2) + ((2*TY_q22 - TY_qa32 - 2*TY_qb32 + 2*TY_qc132)*(TY_q22 + TY_qc223) + (2*TY_q22 - TY_qa23 + 2*(-TY_qb23 + TY_qc123 + TY_qc223))*TY_qc232)*pow(Z2,3)) 
    920972                           
    921         TY_B34 = -6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(2*TY_qc223*TY_qc232*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*t1 + exp(2*Z2)*(-2*t2*(Z1 + Z2)*pow(Z2,2) + exp(Z1)*t6))*pow(Z1 + Z2,-1); 
     973        TY_B34 = -6*phi*exp(-Z1 - 2*Z2)*pow(TY_q22,-2)*pow(Z2,-3)*(2*TY_qc223*TY_qc232*(Z1 + Z2)*exp(Z1)*pow(Z2,2) + 2*exp(Z2)*t1 + exp(2*Z2)*(-2*t2*(Z1 + Z2)*pow(Z2,2) + exp(Z1)*t6))*pow(Z1 + Z2,-1) 
    922974         
    923975 
     
    11131165        TY_w[3] += -TY_B24*TY_G14*TY_G23 - TY_B23*TY_G15*TY_G23 - TY_B22*TY_G16*TY_G23 - TY_B21*TY_G17*TY_G23 - TY_B24*TY_G13*TY_G24 - TY_B23*TY_G14*TY_G24 - TY_B22*TY_G15*TY_G24 - TY_B21*TY_G16*TY_G24 + 2*TY_B14*TY_G23*TY_G24   
    11141166        TY_w[3] += -TY_B23*TY_G13*TY_G25 - TY_B22*TY_G14*TY_G25 - TY_B21*TY_G15*TY_G25 + 2*TY_B14*TY_G22*TY_G25 + 2*TY_B12*TY_G24*TY_G25 - TY_B22*TY_G13*TY_G26 - TY_B21*TY_G14*TY_G26 + 2*TY_B12*TY_G23*TY_G26 - TY_B21*TY_G13*TY_G27  
    1115         TY_w[3] += 2*TY_B12*TY_G22*TY_G27; 
     1167        TY_w[3] += 2*TY_B12*TY_G22*TY_G27 
    11161168         
    11171169        TY_w[4] = -(TY_B25*TY_G15*TY_G22) - TY_B24*TY_G16*TY_G22 - TY_B23*TY_G17*TY_G22 - TY_B22*TY_G18*TY_G22 - TY_B21*TY_G19*TY_G22 - TY_B25*TY_G14*TY_G23 - TY_B24*TY_G15*TY_G23 - TY_B23*TY_G16*TY_G23 - TY_B22*TY_G17*TY_G23   
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Teubner_v40.ipf

    r570 r931  
    77// 
    88// 06 NOV 98 SRK 
     9// 
     10// JAN 2014 - SRK 
     11// 
     12// Changed the input parameters to be the length scales rather than a2, c1, c2 
     13// which have no physical meaning. 
    914//////////////////////////////////////////////// 
    1015 
     
    1722        Make/O/D/n=(num) xwave_ts,ywave_ts 
    1823        xwave_ts =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num)) 
    19         Make/O/D coef_ts = {0.1,-30,5000,0.1} 
    20         make/o/t parameters_ts = {"scale (a2)","c1","c2","bkg"} 
     24//      Make/O/D coef_ts = {0.1,-30,5000,0.1} 
     25//      make/o/t parameters_ts = {"scale (a2)","c1","c2","bkg"} 
     26 
     27        Make/O/D coef_ts = {0.3,6e-6,30,100,0.1} 
     28        make/o/t parameters_ts = {"scale","SLD difference (A^-2)","correlation length (xi) (A)","repeat distance, d, (A)","bkg (1/cm)"} 
     29 
    2130        Edit parameters_ts,coef_ts 
    2231        Variable/G root:g_ts 
     
    4756         
    4857        // Setup parameter table for model function 
    49         Make/O/D smear_coef_ts = {0.1,-30,5000,0.1} 
    50         make/o/t smear_parameters_ts = {"scale (a2)","c1","c2","bkg"} 
     58        Make/O/D smear_coef_ts = {0.3,6e-6,30,100,0.1} 
     59        make/o/t smear_parameters_ts = {"scale","SLD difference (A^-2)","correlation length (xi) (A)","repeat distance, d, (A)","bkg (1/cm)"} 
    5160        Edit smear_parameters_ts,smear_coef_ts 
    5261         
     
    7382        Wave cw,yw,xw 
    7483 
     84        Variable a2, c1, c2 
     85        Variable d,xi,scale,delrho 
     86 
     87        scale = cw[0] 
     88        delrho = cw[1] 
     89        xi = cw[2] 
     90        d = cw[3] 
     91         
     92         
     93        a2 = (1 + (2*pi*xi/d)^2)^2 
     94        c1 = -2*xi*xi*(2*pi*xi/d)^2+2*xi*xi 
     95        c2 = xi^4        
     96         
     97        a2 /= 8*pi*xi^3*scale*delrho^2*1e8              //this makes the units work out 
     98        c1 /= 8*pi*xi^3*scale*delrho^2*1e8 
     99        c2 /= 8*pi*xi^3*scale*delrho^2*1e8 
     100         
     101//      Print a2,c1,c2 
     102 
     103        Duplicate/O cw tmp_ts_cw 
     104        tmp_ts_cw[0] = a2 
     105        tmp_ts_cw[1] = c1 
     106        tmp_ts_cw[2] = c2 
     107        tmp_ts_cw[3] = cw[4] 
     108         
    75109#if exists("TeubnerStreyModelX") 
    76         yw = TeubnerStreyModelX(cw,xw) 
     110        yw = TeubnerStreyModelX(tmp_ts_cw,xw) 
    77111#else 
    78         yw = fTeubnerStreyModel(cw,xw) 
     112        yw = fTeubnerStreyModel(tmp_ts_cw,xw) 
    79113#endif 
    80114        return(0) 
     
    109143        Endif 
    110144        // calculate the correlation length and the repeat distance 
    111         Variable a2,c1,c2,xi,dd 
    112         a2 = coef_ts[0] 
    113         c1 = coef_ts[1] 
    114         c2 = coef_ts[2] 
    115          
    116         xi = 0.5*sqrt(a2/c2) + c1/4/c2 
    117         xi = 1/sqrt(xi) 
    118          
    119         dd = 0.5*sqrt(a2/c2) - c1/4/c2 
    120         dd = 1/sqrt(dd) 
    121         dd *=2*Pi 
    122          
     145//      Variable a2,c1,c2,xi,dd,fa 
     146//      a2 = coef_ts[0] 
     147//      c1 = coef_ts[1] 
     148//      c2 = coef_ts[2] 
     149//       
     150//      xi = 0.5*sqrt(a2/c2) + c1/4/c2 
     151//      xi = 1/sqrt(xi) 
     152//       
     153//      dd = 0.5*sqrt(a2/c2) - c1/4/c2 
     154//      dd = 1/sqrt(dd) 
     155//      dd *=2*Pi 
     156//               
     157 
     158        Variable a2, c1, c2 
     159        Variable d,xi,scale,delrho,fa 
     160        xi = coef_ts[2] 
     161        d = coef_ts[3] 
     162         
     163         
     164        a2 = (1 + (2*pi*xi/d)^2)^2 
     165        c1 = -2*xi*xi*(2*pi*xi/d)^2+2*xi*xi 
     166        c2 = xi^4        
     167         
     168        fa = c1/(sqrt(4*a2*c2)) 
     169                 
    123170        Printf "The correlation length (the dispersion of d) xi = %g A\r",xi 
    124         Printf "The quasi-periodic repeat distance, d = %g A\r",dd 
     171        Printf "The quasi-periodic repeat distance, d = %g A\r",d 
     172        Printf "The amphiphilicity factor, fa = %g\r",fa 
    125173         
    126174End 
Note: See TracChangeset for help on using the changeset viewer.