0001
0002
0003 function [calmat fval hessian] = polcal2(data, model)
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 calmat0 = [1,1,0,0,0,0;...
0024 0,0,1,1,0,0;...
0025 0,0,0,0,1,1];
0026
0027
0028
0029
0030 options = optimset('PlotFcns',@optimplotfval,'TolFun',1e-18);
0031 [calmat, fval, hessian] = fminunc(@chisq, calmat0,options)
0032
0033
0034
0035
0036
0037
0038
0039 figure
0040 k=0
0041
0042 for z=1:3
0043 for w=1:6
0044 calmat_temp=calmat;
0045 k=k+1;
0046
0047 m=0;
0048 for l=-0.5:0.01:0.5
0049 m=m+1;
0050 calmat_temp(z,w)=calmat(z,w)+l;
0051 chisq_temp(m)=chisq(calmat_temp);
0052 x(m)=calmat(z,w)+l;
0053 end
0054 subplot(3,6,k)
0055
0056 plot(x,chisq_temp)
0057 hold all
0058 plot(calmat(z,w),chisq(calmat),'or')
0059
0060 [minval minpos]=min(chisq_temp);
0061
0062
0063 end
0064
0065 end
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 function f = chisq(calmat)
0083 f = 0;
0084 npoints = length(data(:,1));
0085 for i = 1:npoints;
0086 phi = -data(i,7);
0087 modelvec = [model(1), model(1)*model(2)*cosd(2*(model(3)+phi)), model(1)*model(2)*sind(2*(model(3)+phi))];
0088 datavec = [data(i,1), data(i,2), data(i,3),data(i,4), data(i,5), data(i,6)];
0089 chi = modelvec*calmat - datavec;
0090
0091 f = f + norm(chi)^2;
0092 end
0093 end
0094
0095 function g = chi(calmat)
0096 g = [];
0097 npoints = length(data(:,1));
0098 for i = 1:npoints;
0099 phi = -data(i,7);
0100 modelvec = [model(1), model(1)*model(2)*cosd(2*(model(3)+phi)), model(1)*model(2)*sind(2*(model(3)+phi))];
0101 datavec = [data(i,1), data(i,2), data(i,3),data(i,4), data(i,5), data(i,6)];
0102
0103 chi = modelvec*calmat - datavec;
0104 g = [g,chi];
0105 end
0106 end
0107
0108 function h = check(data,model)
0109 h = 0;
0110 npoints = length(data(:,1));
0111 for i = 1:npoints;
0112 phi = -data(i,7);
0113 modelvec = [model(1), model(1)*model(2)*cosd(2*(model(3)+phi)), model(1)*model(2)*sind(2*(model(3)+phi))];
0114 datavec = [data(i,1), data(i,2), data(i,3),data(i,4), data(i,5), data(i,6)];
0115 h = modelvec*calmat - datavec;
0116
0117
0118 end
0119 end
0120
0121
0122
0123 end
0124