%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Matlab/Simulink program for Results comparison %%%%%%%
%%%%%%% between full ANSYS and reduced MOR simulations %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Pascal Maglie %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% maglie@iwf.mavt.ethz.ch %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% IWF - Institut für Werkzeugmaschinen und Fertigung %%%%%
%%%%% ETHZ - Eidgenössische Technische Hochschule Zürich %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
close all;
% Choose working directory
cd Z:\
% program for writing of state-space matrices in Matlab format
state_space_model;
% run Simulink simulation of the reduced model
sim ansys_mor_comp_sim
% load data from ANSYS full simulation
load fixstep.m
% Rem: add a "zero" at the beginning of the time and outputs vectors
% plots for comparison of reduced and full simulations
figure(1);
plot(time,point1,time,fixstep(:,2));
grid on;
title('back');
legend('mor20','ansys');
xlabel('time (s)');
ylabel('deltaZ (mm)');
saveas(gcf,'point1','emf');
figure(2);
plot(time,point2,time,fixstep(:,3));
grid on;
title('front');
legend('mor20','ansys');
xlabel('time (s)');
ylabel('deltaZ (mm)');
saveas(gcf,'point2','emf');
figure(3);
plot(time,point1-fixstep(:,2));
grid on;
title('back');
xlabel('time (s)');
ylabel('diff (mm)');
saveas(gcf,'difference 1','emf');
figure(4);
plot(time,point2-fixstep(:,3));
grid on;
title('front');
xlabel('time (s)');
ylabel('diff (mm)');
saveas(gcf,'difference 2','emf');
figure(5);
plot(time,(point1-fixstep(:,2))./point1*100);
grid on;
title('back');
xlabel('time (s)');
ylabel('%');
saveas(gcf,'relative error 1','emf');
figure(6);
plot(time,(point2-fixstep(:,3))./point2*100);
grid on;
title('front');
xlabel('time (s)');
ylabel('%');
saveas(gcf,'relative error 2','emf');