function mod_inverse_prob(q_guess) % Modified Inverse Least Squares Estimation Problem % Implementation of the inverse problem which finds the optimal values for the % parameters C and K for the vibrating beam (damped or undamped model) % using the least squares function % q_guess, vector with guess values for the paramters C and K, % where q_guess(1) = C = c/m and q_guess(2) = K = k/m % J_q_guess, cost function value associated with the guess values for C and % K (residual) % q_optimal, optimal values for C and K % J_q_optimal, cost function value associated with the optimal values % for C and K (residual) % variance_hat, variance associated with the optimal values for C and K initial_t = load('trac3.x'); % reads in time data for frequency of 6.15 Hz initial_a = load('trac3.txt'); % reads in acceleration data for frequency of 6.15 Hz % find index of a peak acceleration point (corresponds to maximum displacement) max_val = find(initial_a==max(initial_a)); t = initial_t(max_val:1024); % change indexing of the time and acceleration data a = initial_a(max_val:1024); % plot data figure (1) plot(t,a,'r--') % plot of acceleration data versus time grid on xlabel('Time') ylabel('Acceleration') title('Beam Acceleration Data') % initial conditions (initial displacement = -(y"(t)/K and initial velocity = 0) IC = [(-a(1)/q_guess(2));0]; a = a - mean(a); % center acceleration data about 0 % Use undamped model if C = 0, otherwise use damped model if (q_guess(1) == 0) % cost associated with guess for K J_q_guess = undamped_cost_func(q_guess,t,a,IC) % find the optimal value for K and the associated cost function value [q_optimal,J_q_optimal] = fminsearch(@undamped_cost_func,q_guess,[],t,a,IC) % compute the solution to the undamped spring-mass-dashpot system using % optimal K value mod_sol = undamped_mod_sol(q_optimal(2),t,IC); % compute the acceleration values from the model with optimal K a_mod = -q_optimal(2)*mod_sol(:,1); else % cost associated with the guess values for C and K J_q_guess = damped_cost_func(q_guess,t,a,IC) % find the optimal values for C and K and the associated cost function % value [q_optimal,J_q_optimal] = fminsearch(@damped_cost_func,q_guess,[],t,a,IC) % compute the solution to the damped spring-mass-dashpot system using % the optimal values for C and K mod_sol = damped_mod_sol(q_optimal(1),q_optimal(2),t,IC); % compute the acceleration values from the model with optimal C and K a_mod = -q_optimal(1)*mod_sol(:,2) - q_optimal(2)*mod_sol(:,1); end % variance associated with the optimal C* and K* variance_hat = (1/(length(a)-length(q_optimal)))*length(a)*J_q_optimal r_j = a - a_mod; % residuals between acceleration data and acceleration from model % Plots figure (2) plot(t,a_mod,'b-v',t,a,'r-*') % plot of acceleration data and acceleration from model versus time legend('model','experiment') grid on xlabel('Time') ylabel('Acceleration') title('Model versus Experimental Data') figure (3) plot(t,r_j,'r+') % plot of errors versus time grid on xlabel('Time') ylabel('Error') title('Error versus time')