%l1.m
l1base=[1286844.94217272; 1286845.76023910; 1286846.57145452; 1286847.37017918; 1286848.15226064; 1286848.91478877; 1286849.65578306; 1286850.37401913; 1286851.06884239; 1286851.74003085; 1286852.38769300; 1286853.01216340; 1286853.61396048; 1286854.19371620; 1286854.75214874; 1286855.29001803; 1286855.80811504; 1286856.30724567; 1286856.78820634; 1286857.25178400; 1286857.69874439]
l1b1=[1286918.82352204; 1286912.50269106; 1286907.02672048; 1286902.24609953; 1286898.04355643; 1286894.32584049; 1286891.01813942; 1286888.05972834; 1286885.40093968; 1286883.00075388; 1286880.82508513; 1286878.84540078; 1286877.03764768; 1286875.38142312; 1286873.85934011; 1286872.45649603; 1286871.16005819; 1286869.95889447; 1286868.84335381; 1286867.80499596; 1286866.83643674]
l1b2=[1287505.18151730; 1287472.09167122; 1287445.13617005; 1287422.66758678; 1287403.59560467; 1287387.16633740; 1287372.84053745; 1287360.22061503; 1287349.00639116; 1287338.96621213; 1287329.91821772; 1287321.71737344; 1287314.24633716; 1287307.40902490; 1287301.12595475; 1287295.33073566; 1287289.96743034; 1287284.98842978; 1287280.35310897; 1287276.02643224; 1287271.97810223]
l1b3=[1286844.94217500; 1286845.76024014; 1286846.57145502; 1286847.37017942; 1286848.15226077; 1286848.91478884; 1286849.65578310; 1286850.37401915; 1286851.06884241; 1286851.74003085; 1286852.38769300; 1286853.01216340; 1286853.61396048; 1286854.19371620; 1286854.75214874; 1286855.29001803; 1286855.80811504; 1286856.30724567; 1286856.78820634; 1286857.25178400; 1286857.69874439]
l1b4=[1286844.94066406; 1286845.75922094; 1286846.57075056; 1286847.36968193; 1286848.15190265; 1286848.91452661; 1286849.65558810; 1286850.37387211; 1286851.06873011; 1286851.73994409; 1286852.38762525; 1286853.01210997; 1286853.61391797; 1286854.19368209; 1286854.75212115; 1286855.28999555; 1286855.80809661; 1286856.30723046; 1286856.78819371; 1286857.25177345; 1286857.69873554]
l1b5=[1286844.94988023; 1286845.76195557; 1286846.57190639; 1286847.37031515; 1286848.15230629; 1286848.91480556; 1286849.65578973; 1286850.37402196; 1286851.06884367; 1286851.74003145; 1286852.38769329; 1286853.01216355; 1286853.61396056; 1286854.19371624; 1286854.75214877; 1286855.29001804; 1286855.80811505; 1286856.30724567; 1286856.78820634; 1286857.25178400; 1286857.69874439]
l1b6=[1286844.85381714; 1286845.71838501; 1286846.54987488; 1286847.35827022; 1286848.14531157; 1286848.91054053; 1286849.65308134; 1286850.37224173; 1286851.06763823; 1286851.73919383; 1286852.38709786; 1286853.01173166; 1286853.61364162; 1286854.19347689; 1286854.75196651; 1286855.28987744; 1286855.80800527; 1286856.30715902; 1286856.78813726; 1286857.25172842; 1286857.69869929]
l1gauss=[-1545620.34395791; -1545671.47821991; -1545688.22386083; -1545690.71821834; -1545687.64544868; -1545682.67683282; -1545677.33955551; -1545672.23790543; -1545667.60239696; -1545663.45753177; -1545659.77769367; -1545656.49107514; -1545653.55470184; -1545650.90842906; -1545648.51517741; -1545646.33102648; -1545644.44889001; -1545642.79334975; -1545641.31764608; -1545639.99088677; -1545638.78967407]
%l2.m
l2base=[1286844.12477431]
l2b1=[1286926.18228656]
l2b2=[1287547.03086908]
l2b3=[1286844.12477959]
l2b4=[1286844.12247633]
l2b5=[1286844.16769623]
l2b6=[1286843.91684115]
l2gauss=[-1545489.45213527]
%l3.m
l3base=[1283353.84389224; 1283354.18770913; 1283354.54543066; 1283354.91480740; 1283355.29376643; 1283355.68037571; 1283356.07289356; 1283356.46973375; 1283356.86947114; 1283357.27083471; 1283357.67270567; 1283358.07408747; 1283358.47411137; 1283358.87203039; 1283359.26717964; 1283359.65900627]
l3b1=[1283480.89339461; 1283473.32530408; 1283466.49037728; 1283460.29255649; 1283454.65151862; 1283449.49979309; 1283444.77999483; 1283440.44316784; 1283436.44739657; 1283432.75639372; 1283429.33868495; 1283426.16694355; 1283423.21716754; 1283420.46827028; 1283417.90174328; 1283415.50112862]
l3b2=[1284125.10416693; 1284106.48201800; 1284088.67165404; 1284071.71987809; 1284055.64253966; 1284040.43374218; 1284026.07160928; 1284012.52410842; 1283999.75327296; 1283987.71732319; 1283976.37310266; 1283965.67783991; 1283955.58945106; 1283946.06748761; 1283937.07382383; 1283928.57224169]
l3b3=[1283353.84413638; 1283354.18784507; 1283354.54550845; 1283354.91485303; 1283355.29379381; 1283355.68039248; 1283356.07290403; 1283356.46974042; 1283356.86947545; 1283357.27083754; 1283357.67270755; 1283358.07408874; 1283358.47411223; 1283358.87203099; 1283359.26718006; 1283359.65900657]
l3b4=[1283353.82826726; 1283354.17604951; 1283354.53661075; 1283354.90805227; 1283355.28853365; 1283355.67627970; 1283356.06965642; 1283356.46715258; 1283356.86739598; 1283357.26915354; 1283357.67133393; 1283358.07296072; 1283358.47318004; 1283358.87125608; 1283359.26653231; 1283359.65846228]
l3b5=[1283353.84854976; 1283354.19055963; 1283354.54717515; 1283354.91587810; 1283355.29442696; 1283355.68078598; 1283356.07315044; 1283356.46989604; 1283356.86957464; 1283357.27090137; 1283357.67274903; 1283358.07411597; 1283358.47413028; 1283358.87204307; 1283359.26718822; 1283359.65901213]
l3b6=[1283353.74658500; 1283354.11153820; 1283354.48580110; 1283354.86805592; 1283355.25701497; 1283355.65138456; 1283356.04993038; 1283356.45146283; 1283356.85486361; 1283357.25909772; 1283357.66322722; 1283358.06639387; 1283358.46783480; 1283358.86688424; 1283359.26293955; 1283359.65549594]
l3gauss=[-1545606.18519925; -1545643.58226669; -1545670.35140498; -1545688.95917088; -1545701.39381635; -1545709.23730269; -1545713.69864792; -1545715.69310782; -1545715.93402281; -1545714.94280063; -1545713.11568676; -1545710.74633400; -1545708.04331142; -1545705.16174748; -1545702.19959827; -1545699.22004881]
%l4.m
l4base=[1283360.04703196; 1283360.81011967; 1283361.55396458; 1283362.27690955; 1283362.97794292; 1283363.65655811; 1283364.31261075; 1283364.94623833; 1283365.55779230; 1283366.14776270; 1283366.71674341]
l4b1=[1283413.25182563; 1283409.15672197; 1283405.52817254; 1283402.29514239; 1283399.39985245; 1283396.79485206; 1283394.44092367; 1283392.30538235; 1283390.36076751; 1283388.58391528; 1283386.95514295]
l4b2=[1283920.52886531; 1283905.69330748; 1283892.34121198; 1283880.27927748; 1283869.34259273; 1283859.39047331; 1283850.30307368; 1283841.97797201; 1283834.32727748; 1283827.27554457; 1283820.75768118]
l4b3=[1283360.04703217; 1283360.81011978; 1283361.55396464; 1283362.27690958; 1283362.97794294; 1283363.65655812; 1283364.31261076; 1283364.94623834; 1283365.55779230; 1283366.14776270; 1283366.71674341]
l4b4=[1283360.04657257; 1283360.80978755; 1283361.55372044; 1283362.27672737; 1283362.97780511; 1283363.65645256; 1283364.31252899; 1283364.94617433; 1283365.55774172; 1283366.14772237; 1283366.71671099]
l4b5=[1283360.04703601; 1283360.81012164; 1283361.55396558; 1283362.27691007; 1283362.97794320; 1283363.65655826; 1283364.31261084; 1283364.94623838; 1283365.55779233; 1283366.14776272; 1283366.71674342]
l4b6=[1283360.04411221; 1283360.80807237; 1283361.55250447; 1283362.27585159; 1283362.97716499; 1283363.65597822; 1283364.31217297; 1283364.94590392; 1283365.55753404; 1283366.14756122; 1283366.71658472]
l4gauss=[-1545696.27464056; -1545690.59537837; -1545685.28061706; -1545680.39998082; -1545675.94780601; -1545671.91657461; -1545668.26418474; -1545664.95512188; -1545661.94892271; -1545659.20866267; -1545656.70089492]
%l5.m
l5base=[1283349.36398601; 1283350.87238202; 1283352.20580973; 1283353.38618756; 1283354.43215424; 1283355.35921479; 1283356.18015935; 1283356.90553705; 1283357.54402791; 1283358.10280903; 1283358.58777193; 1283359.00378679; 1283359.35482499; 1283359.64410128; 1283359.87417587]
l5b1=[1283430.83049451; 1283432.33889852; 1283433.67233864; 1283434.85272648; 1283435.89868519; 1283436.82573839; 1283437.64668225; 1283438.37206026; 1283439.01058049; 1283439.56932689; 1283440.05432302; 1283440.47031916; 1283440.82135249; 1283441.11064479; 1283441.34071796]
l5b2=[1283979.81214214; 1283984.92688389; 1283989.70597982; 1283994.06779629; 1283997.92712076; 1284001.20430640; 1284003.83533772; 1284005.78146699; 1284007.03612870; 1284007.62719102; 1284007.61577286; 1284007.08849199; 1284006.14963987; 1284004.91062960; 1284003.48108913]
l5b3=[1283349.36399121; 1283350.87238722; 1283352.20581493; 1283353.38619276; 1283354.43215944; 1283355.35921999; 1283356.18016455; 1283356.90554225; 1283357.54403311; 1283358.10281423; 1283358.58777714; 1283359.00379199; 1283359.35483019; 1283359.64410649; 1283359.87418107]
l5b4=[1283349.36170466; 1283350.87010067; 1283352.20352837; 1283353.38390620; 1283354.42987289; 1283355.35693343; 1283356.17787800; 1283356.90325570; 1283357.54174655; 1283358.10052768; 1283358.58549058; 1283359.00150544; 1283359.35254363; 1283359.64181993; 1283359.87189451]
l5b5=[1283349.36406708; 1283350.87246943; 1283352.20590472; 1283353.38629096; 1283354.43226609; 1283355.35933400; 1283356.18028363; 1283356.90566314; 1283357.54415220; 1283358.10292827; 1283358.58788383; 1283359.00389027; 1283359.35492008; 1283359.64418883; 1283359.87425712]
l5b6=[1283349.35160788; 1283350.85931355; 1283352.19202321; 1283353.37169613; 1283354.41702311; 1283355.34356637; 1283356.16416889; 1283356.88941733; 1283357.52800502; 1283358.08709497; 1283358.57254019; 1283358.98915717; 1283359.34085900; 1283359.63080722; 1283359.86151989]
l5gauss=[-1545713.00579208; -1545713.92518483; -1545714.62679335; -1545715.18013860; -1545715.59135979; -1545715.86540780; -1545715.99901891; -1545715.98849748; -1545715.83167233; -1545715.51525960; -1545715.02184417; -1545714.34097805; -1545713.47325155; -1545712.44236530; -1545711.29580994]
%l6.m
l6base=[1085698.87540946; 1085700.01856144; 1085701.12048788; 1085702.17891335; 1085703.19306121; 1085704.16319794; 1085705.09027134; 1085705.97566955; 1085706.82104952; 1085707.62820706; 1085708.39901062; 1085709.13533444; 1085709.83901768; 1085710.51184939; 1085711.15553307; 1085711.77170395; 1085712.36190490; 1085712.92759507; 1085713.47014698; 1085713.99084480; 1085714.49089742]
l6b1=[1085860.26402299; 1085838.33074158; 1085820.97148771; 1085806.92526331; 1085795.35224931; 1085785.67172521; 1085777.46965810; 1085770.44311903; 1085764.36553507; 1085759.06421542; 1085754.40526794; 1085750.28338662; 1085746.61469162; 1085743.33153763; 1085740.37889292; 1085737.71145504; 1085735.29168575; 1085733.08819871; 1085731.07457857; 1085729.22845881; 1085727.53075552]
l6b2=[1086496.43383297; 1086461.52147787; 1086428.75797516; 1086398.58339117; 1086371.10379400; 1086346.23414812; 1086323.79266574; 1086303.55788039; 1086285.30106330; 1086268.80336417; 1086253.86358201; 1086240.30120471; 1086227.95662711; 1086216.68969623; 1086206.37822660; 1086196.91552629; 1086188.20875506; 1086180.17693848; 1086172.74941441; 1086165.86445236; 1086159.46789216]
l6b3=[1085698.87896216; 1085700.01942587; 1085701.12073202; 1085702.17899114; 1085703.19308859; 1085704.16320842; 1085705.09027565; 1085705.97567143; 1085706.82105039; 1085707.62820748; 1085708.39901083; 1085709.13533455; 1085709.83901774; 1085710.51184942; 1085711.15553309; 1085711.77170396; 1085712.36190491; 1085712.92759508; 1085713.47014698; 1085713.99084480; 1085714.49089742]
l6b4=[1085698.81580490; 1085699.98916025; 1085701.10486288; 1085702.17009346; 1085703.18782844; 1085704.15996082; 1085705.08819618; 1085705.97429781; 1085706.82011820; 1085707.62755973; 1085708.39855122; 1085709.13500232; 1085709.83877354; 1085710.51166721; 1085711.15539526; 1085711.77159840; 1085712.36182314; 1085712.92753107; 1085713.47009640; 1085713.99080447; 1085714.49086499]
l6b5=[1085698.87746236; 1085700.01944834; 1085701.12086831; 1085702.17907805; 1085703.19313392; 1085704.16323088; 1085705.09028669; 1085705.97567692; 1085706.82105317; 1085707.62820892; 1085708.39901159; 1085709.13533497; 1085709.83901797; 1085710.51184955; 1085711.15553317; 1085711.77170401; 1085712.36190493; 1085712.92759509; 1085713.47014699; 1085713.99084481; 1085714.49089742]
l6b6=[1085698.79916918; 1085699.96835831; 1085701.08753717; 1085702.15718452; 1085703.17859272; 1085704.15344129; 1085705.08359817; 1085705.97103741; 1085706.81778622; 1085707.62587460; 1085708.39732012; 1085709.13409287; 1085709.83809430; 1085710.51115448; 1085711.15500426; 1085711.77129730; 1085712.36158912; 1085712.92734758; 1085713.46995133; 1085713.99068887; 1085714.49077220]
l6gauss=[-1545433.64426959; -1545532.23952288; -1545583.25804708; -1545607.13695772; -1545616.30661010; -1545617.79090725; -1545615.40316253; -1545611.19997571; -1545606.26849100; -1545601.18252487; -1545596.23081845; -1545591.56176942; -1545587.22444257; -1545583.23870818; -1545579.58757455; -1545576.24786069; -1545573.18841608; -1545570.38046097; -1545567.79345063; -1545565.40224372; -1545563.18530289]

l1d1=l1b1-l1base;
l1d2=l1b2-l1base;
l1d3=l1b3-l1base;
l1d4=l1b4-l1base;
l1d5=l1b5-l1base;
l1d6=l1b6-l1base;

l2d1=l2b1-l2base;
l2d2=l2b2-l2base;
l2d3=l2b3-l2base;
l2d4=l2b4-l2base;
l2d5=l2b5-l2base;
l2d6=l2b6-l2base;

l3d1=l3b1-l3base;
l3d2=l3b2-l3base;
l3d3=l3b3-l3base;
l3d4=l3b4-l3base;
l3d5=l3b5-l3base;
l3d6=l3b6-l3base;

l4d1=l4b1-l4base;
l4d2=l4b2-l4base;
l4d3=l4b3-l4base;
l4d4=l4b4-l4base;
l4d5=l4b5-l4base;
l4d6=l4b6-l4base;

l5d1=l5b1-l5base;
l5d2=l5b2-l5base;
l5d3=l5b3-l5base;
l5d4=l5b4-l5base;
l5d5=l5b5-l5base;
l5d6=l5b6-l5base;

l6d1=l6b1-l6base;
l6d2=l6b2-l6base;
l6d3=l6b3-l6base;
l6d4=l6b4-l6base;
l6d5=l6b5-l6base;
l6d6=l6b6-l6base;

l1d=[l1d1 l1d2 l1d3 l1d4 l1d5 l1d6];
l2d=[l2d1 l2d2 l2d3 l2d4 l2d5 l2d6];
l3d=[l3d1 l3d2 l3d3 l3d4 l3d5 l3d6];
l4d=[l4d1 l4d2 l4d3 l4d4 l4d5 l4d6];
l5d=[l5d1 l5d2 l5d3 l5d4 l5d5 l5d6];
l6d=[l6d1 l6d2 l6d3 l6d4 l6d5 l6d6];

fit_0=[1.5124; -0.6320; 2903.17; 136.74; 1267; 85.44]
fit_1=[2.3464; -0.9100; 36000; 136.74; 19000; 85.44]

fit=fit_1

l1g=l1gauss-min(l1gauss)
l2g=l2gauss-min(l2gauss)
l3g=l3gauss-min(l3gauss)
l4g=l4gauss-min(l4gauss)
l5g=l5gauss-min(l5gauss)
l6g=l6gauss-min(l6gauss)

[s,]=size(l1g)
x=transpose(1:s)
l1g=l1gauss-min(l1gauss)
l2g=l2gauss-min(l2gauss)
l3g=l3gauss-min(l3gauss)
l4g=l4gauss-min(l4gauss)
l5g=l5gauss-min(l5gauss)
l6g=l6gauss-min(l6gauss)

mat1=[l1g]
mat2=[l2g]
mat3=[l3g]
mat4=[l4g]
mat5=[l5g]
mat6=[l6g]
matp=[0]
matviga=[0]

count=0;
for p = 0.9:0.01:1.1
count=count+1
%	q=0.215*p
%	fit=[1.5124+3*q; -0.6320-q; 36400; 1.0; 17800; 9.5]
	fit=[1.5124; -0.6320; 36400*p; 1.0; 17800; 9.5]

l1v=l1base+l1d*fit
l2v=l2base+l2d*fit
l3v=l3base+l3d*fit
l4v=l4base+l4d*fit
l5v=l5base+l5d*fit
l6v=l6base+l6d*fit

l1v=l1v-min(l1v)
l2v=l2v-min(l2v)
l3v=l3v-min(l3v)
l4v=l4v-min(l4v)
l5v=l5v-min(l5v)
l6v=l6v-min(l6v)

mat1=[mat1,l1v]
mat2=[mat2,l2v]
mat3=[mat3,l3v]
mat4=[mat4,l4v]
mat5=[mat5,l5v]
mat6=[mat6,l6v]

l1r=sum((l1v-l1g).^2)
l2r=sum((l2v-l2g).^2)
l3r=sum((l3v-l3g).^2)
l4r=sum((l4v-l4g).^2)
l5r=sum((l5v-l5g).^2)
l6r=sum((l6v-l6g).^2)

r=l1r+l2r+l3r+l4r+l5r+l6r
matp=[matp; p]
matviga=[matviga; r]

end

subplot(3,2,1); plot(mat1)
subplot(3,2,2); plot(mat3)
subplot(3,2,3); plot(mat4)
subplot(3,2,4); plot(mat5)
subplot(3,2,5); plot(mat6)
subplot(3,2,6); plot(matp(2:count+1),matviga(2:count+1))
