位移因子计算
function distance=shift(a,b)global t0 t2 y0 y2 x1;
y0=b(1,2);
y2=a(end,2);
if y0<y2
disp('error');
distance=0;
return;
end
t0=find_x(y0,a);
t2=find_x(y2,b);
x1=find_x(y0,b);
t1=a(end,1);
t_mid=((t0+t1)/2);
t_top=t0;
t_bot=t1;
iteration=1;
while 1
iteration=iteration+1;
y1=find_y(t_mid,a);
x0=find_x(y1,b);
distance=t_mid-x0;
ind=(b(:,2)>y1);
range_b=b(ind,:);
ind=(a(:,2)>y1)&(a(:,2)<y0);
range_a=[;a(ind,:)];
area_t=integral(range_a,range_b,distance,t_mid,y1,1);
ind=(b(:,2)<y1)&(b(:,2)>=y2);
range_b=];
ind=(a(:,2)<y1);
range_a=a(ind,:);
area_b=integral(range_a,range_b,distance,t_mid,y1,2);
fprintf('top=%f, bottom=%f\n',area_t,area_b);
if (abs(area_t-area_b)>1e1)
if area_t<area_b
t_bot=t_mid;
t_mid=(t_top+t_mid)/2;
else
t_top=t_mid;
t_mid=(t_bot+t_mid)/2;
end
if (iteration>20)
disp('iteration hits max times');
break
end
if ((iteration>2)&&(abs(distance_t-distance)<1e-4))
break;
end
else
break
end
distance_t=distance;
end
disp('iteration');
disp(iteration);
页:
[1]