function [cost,d_model]=cost2_beam(CK,time,disp) m=length(disp); weight=ones(m,1); weight(1:2200)=100; weight(3500:m)=2; x0 = [disp(1) 0]; C = CK(1); K = CK(2); [t,x] = ode23(@ode_model, time, x0, [], C, K); d_model = x(:,1); cost = sum(weight.*(d_model-disp).^2);