%%%%%%%%%%%%     Sensitivity Analysis of C3   %%%%%%%%%%%%%
clear;
clc;
%% MODEL 2 
%low frame parameters
m3 = 9.5;
% c3 = 5000;
k3 = 0;
%upper frame parameters
m2 = 7.6;
c2 = 20;
k2 = 3421;
%head parameters
c1 = 5000;
k1 = 10^5;
% catenary mass parameters 
mc0 = 195;
mc1 = 100;
mc2 = 20;
mc3 = 5;
% catenary damping parameters
cc0 = 240;
cc1 = 240;
cc2 = 50;
cc3 = 12;
%catenary stiffness paramwters
kc0 = 7000;
kc1 = 3360;
kc2 = 650;
kc3 = 160;
%static uplift force
F = 100;
%span length
L = 65.52;
%%
%SIMULATION PARAMETERS
TIME_STEP = 0.001;
t_span = 30;
t = [0:TIME_STEP:t_span];
index_start = (t_span-10)/TIME_STEP;

v_max = 100;
v_step = 1;
V_N = v_max/v_step;
C_max = 10000;
C_step = 100;
C_N = C_max/C_step;

[V,C]=meshgrid(1:v_step:v_max,100:C_step:C_max);
J_default = zeros(C_N,V_N);
D_max_default = zeros(C_N,V_N);
F_max_default = zeros(C_N,V_N);
F_min_default = zeros(C_N,V_N);
for i = 1:C_N
    c3 = i*C_step
    for j = 1:V_N
        vv =j*v_step;%velocity
        mc = mc0 + mc1*cos(2*pi*vv*t/L) + mc2*cos(4*pi*vv*t/L) + mc3*cos(6*pi*vv*t/L);
        cc = cc0 + cc1*cos(2*pi*vv*t/L) + cc2*cos(4*pi*vv*t/L) + cc3*cos(6*pi*vv*t/L);
        kc = kc0 + kc1*cos(2*pi*vv*t/L) + kc2*cos(4*pi*vv*t/L) + kc3*cos(6*pi*vv*t/L);
        Mc = [t' mc'];
        Cc = [t' cc'];
        Kc = [t' kc'];
        sim('pantograph_catenery_k1_and_c1_2016a.slx')
        J_default(i,j)  = rms(contact_force.Data( index_start : end ) - F);
        D_max_default(i,j) = max(d_c.Data( index_start : end ));
        F_max_default(i,j) = max(contact_force.Data( index_start : end ));
        F_min_default(i,j) = min(contact_force.Data( index_start : end ));
    end
end
%% SAVE
save('J_default.mat','J_default');% cost function values
save('D_max_default.mat','D_max_default');% panhead displacement values
save('F_max_default.mat','F_max_default');% contact force maximum
save('F_min_default.mat','F_min_default');% contact force minimum

% %% plot
picture




