## trombone.txt

 1 ```/* test */ ``` ```#include "gen.h" ``` ```#include "table.h" ``` ```#include "nrroutines.h" ``` ```#define N 9 ``` ```extern "C" void free_vector(float *data, int nl, int nh); ``` ```extern "C" float *vector(int nl, int nh); ``` ```int trombone(TROMB_STRUCT *tune_set); ``` ```/* Notes: ``` ``` 1. inputs ->delta_q[2] for h/v ``` ``` outputs ->quad_trim[NKNOB] for NKNOB quad trims ``` ``` all other members of the struct are inrelevent in the calc. ``` ``` 2. Calc results - dQh,dQv -> I(quad i) is linear(a straight line fit) ``` ```*/ ``` ```/************************************************************************************************/ ``` ```/* obtain a new setting for the desired tunes by solving the equations obtained in ``` ```* the program in Mathematic. SVD(Singular Value Decomposition) is used to solve the ``` ```* equations. ``` ```* It turns out that 9 families of the trombone quads need to be adjusted independently. There are ``` ```* 6 constrains: betx, alfx, bety, alfy, at two ends of the trombone section, and d_vx, d_vy for ``` ```* the desired tunes. ``` ```* 9 veriables: K1, K2,K3,K4, K5,K6,K7,K8,K9(I=K/L/0.002976536) ``` ```* the 6X9 matrix has been obained from Mathematica program (tromb_fullsection9_2ORM.nb), ``` ```* ``` ```* { -26.0506, 831.49, 59.5737, -749.714, -27.5116, 868.038, 36.4185, -773.266, -12.0946}, ``` ```* { 17.5588, 23.5745, -18.766, -23.7522, 17.585, 8.67871, -19.3967, -10.1126, 17.3344}, ``` ```* {2304.8, -756.055, -1738.19 , 833.257, 1243.97, -829.713, -458.44, 881.6, 67.0388}, ``` ```* { -81.5639, -8.81639, 85.9938, 6.52632 -91.2513, -3.92004, 93.7124, 1.34981,-95.9362}, ``` ```* { 1.41081, 7.9777, 1.55587, 7.25293, 1.41061, 8.0431, 1.55596, 7.193, 1.38011}, ``` ```* { -7.64076, -1.41846, -7.5213, -1.45272, -7.60481, -1.41309, -7.53389, -1.46471, -7.61725}}, ``` ```* ``` ```* the right hand side is ``` ```* {-0.00203665, 0.000291693, -0.156029, -0.000528379, d_Vx,d_vy} ``` ```* Meiqin Xiao, 05/08/2007 ``` ```************************************************************************************************/ ``` ```/************************************************************************************************/ ``` ```/* This is for the new trombone section with 4 trim quads in a group for 601, 602,...609 ``` ```* meiqin xiao, 09/07/2007 ``` ```* obtain a new setting for the desired tunes by solving the equations obtained in ``` ```* the program in Mathematic. SVD(Singular Value Decomposition) is used to solve the ``` ```* equations. ``` ```* It turns out that 9 families of the trombone quads need to be adjusted independently. There are ``` ```* 6 constrains: betx, alfx, bety, alfy, at two ends of the trombone section, and d_vx, d_vy for ``` ```* the desired tunes. ``` ```* 9 veriables: K1, K2,K3,K4, K5,K6,K7,K8,K9(I=K/L/0.002976536) ``` ```* the 6X9 matrix has been obained from Mathematica program (tromb_fullsection9_2ORM.nb), ``` ```* ``` ```* {-140.38, 1688.13, 187.477, -1449.79, -74.7654, 1810.12, 104.737, -1521.67, -49.9376} ``` ```* {33.8252, 68.4684, -35.4021, -50.3818, 36.5726, 37.2133, -37.8437, -26.0246, 35.9651}, ``` ```* {5255.4, -1397.95, -3860.68, 1655.56, 2661.18, -1612.78, -1038.58, 1731.92, 267.428}, ``` ```* {-156.345, -21.1427, 170.255, 12.4532, -181.473, -11.8655,188.58, 6.90345, -191.288}, ``` ```* {2.81678, 16.2875, 3.08217, 14.2611, 2.8848, 16.3927, 3.05359, 14.1942, 2.82223}, ``` ```* {-15.3701, -2.84064, -15.1444, -2.91699, -15.178, -2.83305, -15.182, -2.94246, -15.1916}}, ``` ```* ``` ```* Singular values = {7991.96,2811.64,258.74,37.7007,30.575,23.7899} ``` ```* the right hand side is ``` ```* ``` ```* {-0.104264, 0.018209, -0.173774, 0.00289952, dv_x, dv_y}} ``` ```* ``` ```* Meiqin Xiao, 09/07/2007 ``` ```************************************************************************************************/ ``` ```/************************************************************************************************/ ``` ```/* This is for the new trombone section with 4 trim quads in a group for 601, 602,...609 ``` ```* meiqin xiao, Updated on 10/07/2008 ``` ```* found wierd error during a file transfering format on NewTM_4quad_09072007, resulting mimor ``` ```* changes in the coefficients of the matrix. Update the Console program durin 2008 October ``` ```* Shutdown. Meiqin Xiao, 10/07/2008 ``` ```* ``` ```* obtain a new setting for the desired tunes by solving the equations obtained in ``` ```* the program in Mathematic. SVD(Singular Value Decomposition) is used to solve the ``` ```* equations. ``` ```* It turns out that 9 families of the trombone quads need to be adjusted independently. There are ``` ```* 6 constrains: betx, alfx, bety, alfy, at two ends of the trombone section, and d_vx, d_vy for ``` ```* the desired tunes. ``` ```* 9 veriables: K1, K2,K3,K4, K5,K6,K7,K8,K9(I=K/L/0.002976536) ``` ```* the 6X9 matrix has been obained from Mathematica program (tromb_fullsection9_2ORM.nb), ``` ```* ``` ```* {-128.39, 1598.69, 162.702, -1460.88, -72.362, 1708.54, 82.1163, -1524.1, -48.2942} ``` ```* {32.9211, 62.243, -36.4847, -56.764, 35.2285, 31.0953, -38.943, -32.4888, 34.6596}, ``` ```* {5183.72, -1391.87, -3870.19, 1642.90, 2646.52, -1606.33, -1064.32, 1719.30, 266.015}, ``` ```* {-155.951, -20.9515, 171.254, 12.6403, -180.476, -11.6747,189.573, 7.0916, -190.283}, ``` ```* {2.76783, 15.9378, 3.12461, 14.5062, 2.82823, 16.074, 3.11296, 14.4111, 2.76134}, ``` ```* {-15.2873, -2.84634, -15.0437, -2.91068, -15.2113, -2.83732, -15.10694, -2.93703, -15.2331}}, ``` ```* ``` ```* Singular values = {7927.03,2736.67,256.194,38.7208,27.5055,25.5385} ``` ```* the right hand side is ``` ```* ``` ```* {0.0106982, -0.00289685, 0.208795, 0.00382239, dv_x, dv_y}} ``` ```* ``` ```* Meiqin Xiao, 09/07/2007 ``` ```************************************************************************************************/ ``` ```/************************************************************************************************/ ``` ```/* This is the correction of the coefficients for adjusting the trim quads settings in trombone ``` ``` *section after 2009 Summer Shutdown. The closed orbit has changed, resulting in base tune changed ``` ``` *from (0.417, 0.427) to (0.427,0.436), and beta-function changed about ~5%. Based on this measured ``` ``` * bata-functions at 2 ends(MRK601 and MRK609) and the transfer matrices of the trombone section, ``` ``` * the new coefficents for tunning the tunes has calculated and updated here. ``` ``` * Meiqin Xiao, Nov.17,2009 ``` ```* ``` ```* obtain a new setting for the desired tunes by solving the equations obtained in ``` ```* the program in Mathematic. SVD(Singular Value Decomposition) is used to solve the ``` ```* equations. ``` ```* It turns out that 9 families of the trombone quads need to be adjusted independently. There are ``` ```* 6 constrains: betx, alfx, bety, alfy, at two ends of the trombone section, and d_vx, d_vy for ``` ```* the desired tunes. ``` ```* 9 veriables: K1, K2,K3,K4, K5,K6,K7,K8,K9(I=K/L/0.002976536) ``` ```* the 6X9 matrix has been obained from Mathematica program (tromb_fullsection9_2ORM.nb), ``` ```* ``` ```* {-122.497, 1615.65, 135.61, -1588.11, -65.9322, 1704.44, 47.0098, -1651.3, -49.7233} ``` ```* {34.1466, 59.8896, -36.2102, -52.1996, 35.2765, 27.7801, -38.4453, -26.4248, 35.546}, ``` ```* {5480.38, -1461.7, -3851.28 , 1761.54, 2908.44, -1692.79, -1313.27, 1788.4, 280.657}, ``` ```* {-167.666, -21.7508, 162.204, 9.72964, -191.958, -13.9525,177.936, 4.82235, -200.808}, ``` ```* {2.87133, 15.4478, 3.06023, 14.9975, 2.84258, 15.4768, 3.06936, 14.9874, 2.84597 }, ``` ```* {-15.9904, -2.88911, -14.3305, -2.90138, -16.001, -2.90307, -14.3319, -2.86806, -15.9923}, ``` ```* ``` ```* Singular values = {8316.86,2860.86,250.133,38.3942,30.0983,24.16} ``` ```* the right hand side is ``` ```* ``` ```* {0.00258, 0.0000593, -0.0001, 0.00037726, dv_x, dv_y}} ``` ```* ``` ```* Meiqin Xiao, 09/07/2007 ``` ```************************************************************************************************/ ``` ```/* trombone program by solving the equations using SVD*/ ``` ```int trombone(TROMB_STRUCT *tune_set) ``` ```{ ``` ``` int sts; ``` ```/* float b[9],u[9][9],w[9],v[9][9],x[9];*/ ``` ``` //float value; ``` ``` //char numstr[9]; ``` ``` int i,j,ii; ``` ``` float wmax,wmin; ``` ``` float **u; ``` ``` float **v; ``` ``` float *w; ``` ``` float *b; ``` ``` float *x; ``` ```/* static float a[5][5]={ ``` ``` { 40.33470, 44.4282, -32.6486, 9.4943, 19.9027}, ``` ``` {-167.60400, -7.29578, 183.006, 3.73881, -87.5826}, ``` ``` { 3.23443, 15.729, 2.63187, 15.0529, 1.73248}, ``` ``` { -14.86990, -2.66075, -15.712, -3.10726, -7.18887}, ``` ``` {0. , 0. , 0. , 0. , 0.} ``` ``` };*/ ``` ``` ``` ```/****** the following asignment was for the old trombone section with 2 trim quads in a group******** ``` ```* u=create_matrix(1,N, 1,N); ``` ```* u[1][1]= -26.0506; ``` ```* u[1][2]= 831.49; ``` ```* u[1][3]= 59.5737; ``` ```* u[1][4]= -749.714; ``` ```* u[1][5]= -27.5116; ``` ```* u[1][6]= 868.038; ``` ```* u[1][7]= 36.4185; ``` ```* u[1][8]= -773.266; ``` ```* u[1][9]= -12.0946; ``` ```* ``` ```* u[2][1]= 17.5588; ``` ```* u[2][2]= 23.5745 ; ``` ```* u[2][3]= -18.766; ``` ```* u[2][4]= -23.7522; ``` ```* u[2][5]= 17.585; ``` ```* u[2][6]= 8.67871; ``` ```* u[2][7]= -19.3967; ``` ```* u[2][8]= -10.1126; ``` ```* u[2][9]= 17.3344; ``` ```* ``` ```* u[3][1]= 2304.8; ``` ```* u[3][2]= -756.055; ``` ```* u[3][3]= -1738.19; ``` ```* u[3][4]= 833.257; ``` ```* u[3][5]= 1243.97; ``` ```* u[3][6]= -829.713; ``` ```* u[3][7]= -458.44; ``` ```* u[3][8]= 881.6; ``` ```* u[3][9]= 67.0388; ``` ```* ``` ```* u[4][1]=-81.5639 ; ``` ```* u[4][2]= -8.81639; ``` ```* u[4][3]= 85.9938; ``` ```* u[4][4]= 6.52632; ``` ```* u[4][5]= -91.2513; ``` ```* u[4][6]= -3.92004; ``` ```* u[4][7]= 93.7124; ``` ```* u[4][8]= 1.34981; ``` ```* u[4][9]= -95.9362; ``` ```* ``` ```* u[5][1]= 1.41081; ``` ```* u[5][2]= 7.9777; ``` ```* u[5][3]= 1.55587; ``` ```* u[5][4]= 7.25293; ``` ```* u[5][5]= 1.41061; ``` ```* u[5][6]= 8.0431; ``` ```* u[5][7]= 1.55596; ``` ```* u[5][8]= 7.193; ``` ```* u[5][9]= 1.38011; ``` ```* ``` ```* u[6][1]=-7.64076 ; ``` ```* u[6][2]= -1.41846; ``` ```* u[6][3]= -7.5213; ``` ```* u[6][4]= -1.45272; ``` ```* u[6][5]= -7.60481; ``` ```* u[6][6]= -1.41309; ``` ```* u[6][7]= -7.53389; ``` ```* u[6][8]= -1.46471; ``` ```* u[6][9]= -7.61725; ``` ```* ``` ```* u[7][1]=0.; ``` ```* u[7][2]=0.; ``` ```* u[7][3]=0.; ``` ```* u[7][4]=0.; ``` ```* u[7][5]=0.; ``` ```* u[7][6]=0.; ``` ```* u[7][7]=0.; ``` ```* u[7][8]=0.; ``` ```* u[7][9]=0.; ``` ```* ``` ```* u[8][1]=0.; ``` ```* u[8][2]=0.; ``` ```* u[8][3]=0.; ``` ```* u[8][4]=0.; ``` ```* u[8][5]=0.; ``` ```* u[8][6]=0.; ``` ```* u[8][7]=0.; ``` ```* u[8][8]=0.; ``` ```* u[8][9]=0.; ``` ```* ``` ```* u[9][1]=0.; ``` ```* u[9][2]=0.; ``` ```* u[9][3]=0.; ``` ```* u[9][4]=0.; ``` ```* u[9][5]=0.; ``` ```* u[9][6]=0.; ``` ```* u[9][7]=0.; ``` ```* u[9][8]=0.; ``` ```* u[9][9]=0.; ``` ```******* Meiqin Xiao, updated on 11/17/2009******************/ ``` ``` u=create_matrix(1,N, 1,N); ``` ``` u[1][1]= -122.497; ``` ``` u[1][2]= 1615.65 ; ``` ``` u[1][3]= 135.61; ``` ``` u[1][4]=-1588.11; ``` ``` u[1][5]= -65.9322; ``` ``` u[1][6]= 1704.44; ``` ``` u[1][7]= 47.0098; ``` ``` u[1][8]= -1651.3; ``` ``` u[1][9]= -49.7233; ``` ``` u[2][1]= 34.1466; ``` ``` u[2][2]= 59.8896 ; ``` ``` u[2][3]= -36.2102; ``` ``` u[2][4]= -52.1996; ``` ``` u[2][5]= 35.2765; ``` ``` u[2][6]= 27.7801; ``` ``` u[2][7]= -38.4453; ``` ``` u[2][8]= -26.4248; ``` ``` u[2][9]= 35.546; ``` ``` u[3][1]= 5480.38; ``` ``` u[3][2]= -1461.7 ; ``` ``` u[3][3]= -3851.28; ``` ``` u[3][4]= 1761.54; ``` ``` u[3][5]= 2908.44; ``` ``` u[3][6]= -1692.79; ``` ``` u[3][7]= -1313.27; ``` ``` u[3][8]= 1788.4; ``` ``` u[3][9]= 280.657; ``` ``` u[4][1]= -167.666; ``` ``` u[4][2]= -21.7508; ``` ``` u[4][3]= 162.204; ``` ``` u[4][4]= 9.72964; ``` ``` u[4][5]= -191.958; ``` ``` u[4][6]= -13.9525; ``` ``` u[4][7]= 177.936; ``` ``` u[4][8]= 4.82235; ``` ``` u[4][9]= -200.808; ``` ``` u[5][1]= 2.87133 ; ``` ``` u[5][2]= 15.4478; ``` ``` u[5][3]= 3.06023 ; ``` ``` u[5][4]= 14.9975; ``` ``` u[5][5]= 2.84258; ``` ``` u[5][6]= 15.4768; ``` ``` u[5][7]= 3.06936; ``` ``` u[5][8]= 14.9874; ``` ``` u[5][9]= 2.84597; ``` ``` u[6][1]= -15.9904; ``` ``` u[6][2]= -2.88911; ``` ``` u[6][3]= -14.3305; ``` ``` u[6][4]= -2.90138; ``` ``` u[6][5]= -16.001; ``` ``` u[6][6]= -2.90307; ``` ``` u[6][7]= -14.3319; ``` ``` u[6][8]= -2.86806; ``` ``` u[6][9]= -15.9923; ``` ``` u[7][1]=0.; ``` ``` u[7][2]=0.; ``` ``` u[7][3]=0.; ``` ``` u[7][4]=0.; ``` ``` u[7][5]=0.; ``` ``` u[7][6]=0.; ``` ``` u[7][7]=0.; ``` ``` u[7][8]=0.; ``` ``` u[7][9]=0.; ``` ``` u[8][1]=0.; ``` ``` u[8][2]=0.; ``` ``` u[8][3]=0.; ``` ``` u[8][4]=0.; ``` ``` u[8][5]=0.; ``` ``` u[8][6]=0.; ``` ``` u[8][7]=0.; ``` ``` u[8][8]=0.; ``` ``` u[8][9]=0.; ``` ``` u[9][1]=0.; ``` ``` u[9][2]=0.; ``` ``` u[9][3]=0.; ``` ``` u[9][4]=0.; ``` ``` u[9][5]=0.; ``` ``` u[9][6]=0.; ``` ``` u[9][7]=0.; ``` ``` u[9][8]=0.; ``` ``` u[9][9]=0.; ``` ``` ``` ```/* Copy a into u if you don't want it to be destroyed.*/ ``` ```/* for (i=1;i<=N;i++) ``` ``` for (j=1;j<=N;j++) ``` ``` u[i][j]=a[i][j];*/ ``` ``` sts = 1; ``` ``` ``` ``` v=create_matrix(1,N, 1,N); ``` ``` w=vector( 1,N); ``` ``` b=vector( 1,N); ``` ``` x=vector( 1,N); ``` ```/* The following were for the old trombone section with 2 trim quads in a group ``` ``` * ``` ``` * b[1]=-0.00203665; ``` ``` * b[2]=0.000291693; ``` ``` * b[3]=-0.156029; ``` ``` * b[4]=-0.000528379; ``` ``` * b[5]=tune_set->delta_q[0]; ``` ``` * b[6]=tune_set->delta_q[1]; ``` ``` * b[7]=0; ``` ``` * b[8]=0; ``` ``` * b[9]=0; ``` ``` * assign value to b vector*/ ``` ```/* assign value to b vector, 11/17/2009, Meiqin Xiao*/ ``` ``` ``` ``` b[1]= 0.00258321; ``` ``` b[2]= 0.000059317; ``` ``` b[3]=-0.000148048; ``` ``` b[4]= 0.000377263; ``` ``` b[5]=tune_set->delta_q[0]; ``` ``` b[6]=tune_set->delta_q[1]; ``` ``` b[7]=0; ``` ``` b[8]=0; ``` ``` b[9]=0; ``` ```/*SVD the square matrix a.*/ ``` ``` svdcmp(u,N,N,w,v); ``` ``` wmax=0.0; /* will be the maximum singular value obtained.*/ ``` ``` for (j=1;j<=N;j++) if (w[j]>wmax) wmax=w[j]; ``` ``` wmin=wmax*10e-6; ``` ```/*This is where we set the threshold for singular values allowed to be nonzero. The constant is typical , but not universal. You have to experiment with your own application.*/ ``` ``` for (j=1;j<=N;j++) if (w[j]quad_trim[i]=x[ii]/0.3048/0.00297; ``` ``` if ( tune_set->quad_trim[i] > 6.5 ) { ``` ``` error_message_c("Err: Maximum current exceed 6.5 Amps!", ``` ``` ERR_SIMPLE_DISPLAY,RED); ``` ``` tune_set->quad_trim[i] = 6.5; ``` ``` error_message_c("Caution: The current is repalced by 6.5 Amps!", ``` ``` ERR_SIMPLE_DISPLAY,RED); ``` ``` } ``` ``` if ( tune_set->quad_trim[i] < -6.5 ) { ``` ``` error_message_c("Err: Maximum current exceed -6.5 Amps!", ``` ``` ERR_SIMPLE_DISPLAY,RED); ``` ``` tune_set->quad_trim[i] = -6.5; ``` ``` error_message_c("Caution: The current is repalced by -6.5 Amps!", ``` ``` ERR_SIMPLE_DISPLAY,RED); ``` ``` } ``` ``` } ``` ``` sts = 0; ``` ``` //error_message_c("GOOD SOLUTION!",ERR_SIMPLE_DISPLAY,BLUE); ``` ``` /* ``` ``` for (i = 0; i < 5; i++) { ``` ``` value = tune_set->quad_trim[i]; ``` ``` sprintf(numstr,"%8.3f",value); ``` ``` window_tvm_c(win_dis_id,i+12,10,numstr,8,GREEN); ``` ``` } ``` ``` for (i = 5; i <9; i++) { ``` ``` value = tune_set->quad_trim[i]; ``` ``` sprintf(numstr,"%8.3f",value); ``` ``` window_tvm_c(win_dis_id,20-i,27,numstr,8,GREEN); ``` ``` ``` ``` } ``` ``` */ ``` ``` ``` ``` //memcpy(q_amps,tune_set->quad_trim,NKNOB*sizeof(float)); ``` ``` return (sts); ``` ```} ```