% Least squares estimation of parameters for the spring model % Load and pre-process data -- for all data sets. for example 8 sets of % data Cvec=[]; Kvec=[]; for i=1:8; [time,d_data] = GetData(['data', num2str(i), '.mat']); close all; % starting guesses for parameter values C0=1; K0=1500; q0=[C0;K0]; % minimize the least squares function (cost_beam) [q,cost]=fminsearch(@cost_beam,q0,[],time,d_data); % least squares solutions for C and K C=q(1); K=q(2); Cvec=[Cvec; C]; Kvec=[Kvec; K]; % calculate and plot the fitted model x0=[d_data(1) 0]; %initial conditions [t,x]=ode23(@ode_model,time,x0,[],C,K); %solve the spring model d_model=x(:,1); clear C K d_model d_data time C0 K0 q0; end;