clc; close all; clear; 

load('TAB_quad_rigida');
load('TAB_quad_flessibile');
load('TAB_semplice1');

TAB_semplice_rigid   = TAB_semplice1(string(TAB_semplice1.("Type of wheel"))=="rigid", :);
TAB_semplice_elastic = TAB_semplice1(string(TAB_semplice1.("Type of wheel"))=="elastic", :);

tolMap = containers.Map();
tolMap("Width [m]") = 1e-9;
tolMap("Slip ratio") = 1e-9;
tolMap("Velocity [m/s]") = 1e-9;
tolMap("Vehicle weight [kg]") = 1e-3;

%% Comparison of the 4 models varying only diameter 
% with outputs: Fx Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]

% === RIGID QUADRATIC ===
fixed_qr = containers.Map();

fixed_qr("Width [m]")            = 0.4;
fixed_qr("Number of wheel")      = 6;
fixed_qr("Slip ratio")           = 0.2;
fixed_qr("Velocity [m/s]")       = 5;
fixed_qr("Vehicle weight [kg]")  = 7000;


% === ELASTIC QUADRATIC ===
fixed_qf = containers.Map();

fixed_qf("Width [m]")            = 0.4;
fixed_qf("Number of wheel")      = 6;
fixed_qf("Slip ratio")           = 0.2;
fixed_qf("Velocity [m/s]")       = 5;
fixed_qf("Vehicle weight [kg]")  = 7000;


% === SIMPLE – RIGID ===
fixed_sr = containers.Map();

fixed_sr("Width [m]")               = 0.4;
fixed_sr("Number of wheel")         = 6;
fixed_sr("Slip ratio")              = 0.2;
fixed_sr("Velocity [m/s]")          = 5;
fixed_sr("Vehicle weight [kg]")     = 7000;


% === SIMPLE MODEL (TAB_semplice) ===
fixed_sf = containers.Map();

fixed_sf("Width [m]")            = 0.4;
fixed_sf("Number of wheel")      = 6;
fixed_sf("Slip ratio")           = 0.2;
fixed_sf("Velocity [m/s]")       = 5;
fixed_sf("Vehicle weight [kg]")  = 7000;
fixed_sf("Deflection of the wheel [m]")  = 0.002;


yVars = ["Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]"];
labels4 = {"Rigid quadratic","Elastic quadratic","Rigid constant","Elastic constant"};

for y = yVars
    scatterCompare4Models( ...
        TAB_quad_rigida, TAB_quad_flessibile, TAB_semplice_rigid, TAB_semplice_elastic, ...
        "Diameter [m]", y, ...
        fixed_qr, fixed_qf, fixed_sr, fixed_sf, ...
        labels4, ...
        'Trend',"quadratic", ...
        'Tol',tolMap, ...
        'CVar',"Deflection of the wheel [m]");
end



%% Comparison of the 4 models varying only width 
% with outputs: Fx Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]


% === RIGID QUADRATIC ===
fixed_qr = containers.Map();

fixed_qr("Diameter [m]")         = 0.9;
fixed_qr("Number of wheel")      = 6;
fixed_qr("Slip ratio")           = 0.2;
fixed_qr("Velocity [m/s]")       = 5;
fixed_qr("Vehicle weight [kg]")  = 7000;


% === ELASTIC QUADRATIC ===
fixed_qf = containers.Map();

fixed_qf("Diameter [m]")            = 0.9;
fixed_qf("Number of wheel")      = 6;
fixed_qf("Slip ratio")           = 0.2;
fixed_qf("Velocity [m/s]")       = 5;
fixed_qf("Vehicle weight [kg]")  = 7000;


% === SIMPLE – RIGID ===
fixed_sr = containers.Map();

fixed_sr("Diameter [m]")               = 0.9;
fixed_sr("Number of wheel")         = 6;
fixed_sr("Slip ratio")              = 0.2;
fixed_sr("Velocity [m/s]")          = 5;
fixed_sr("Vehicle weight [kg]")     = 7000;


% === SIMPLE MODEL (TAB_semplice) ===
fixed_sf = containers.Map();

fixed_sf("Diameter [m]")            = 0.9;
fixed_sf("Number of wheel")      = 6;
fixed_sf("Slip ratio")           = 0.2;
fixed_sf("Velocity [m/s]")       = 5;
fixed_sf("Vehicle weight [kg]")  = 7000;
fixed_sf("Deflection of the wheel [m]")  = 0.002;


yVars = ["Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]"];
labels4 = {"Rigid quadratic","Elastic quadratic","Rigid constant","Elastic constant"};

for y = yVars
    scatterCompare4Models( ...
        TAB_quad_rigida, TAB_quad_flessibile, TAB_semplice_rigid, TAB_semplice_elastic, ...
        "Width [m]", y, ...
        fixed_qr, fixed_qf, fixed_sr, fixed_sf, ...
        labels4, ...
        'Trend',"quadratic", ...
        'Tol',tolMap, ...
        'CVar',"Deflection of the wheel [m]");
end

%% Comparison of the 4 models varying only number of wheels
% with outputs: Fx Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]

% === RIGID QUADRATIC ===
fixed_qr = containers.Map();

fixed_qr("Width [m]")            = 0.4;
fixed_qr("Diameter [m]")      = 0.9;
fixed_qr("Slip ratio")           = 0.2;
fixed_qr("Velocity [m/s]")       = 5;
fixed_qr("Vehicle weight [kg]")  = 7000;


% === ELASTIC QUADRATIC ===
fixed_qf = containers.Map();

fixed_qf("Width [m]")            = 0.4;
fixed_qf("Diameter [m]")      = 0.9;
fixed_qf("Slip ratio")           = 0.2;
fixed_qf("Velocity [m/s]")       = 5;
fixed_qf("Vehicle weight [kg]")  = 7000;


% === SIMPLE – RIGID ===
fixed_sr = containers.Map();

fixed_sr("Width [m]")               = 0.4;
fixed_sr("Diameter [m]")         = 0.9;
fixed_sr("Slip ratio")              = 0.2;
fixed_sr("Velocity [m/s]")          = 5;
fixed_sr("Vehicle weight [kg]")     = 7000;


% === SIMPLE MODEL (TAB_semplice) ===
fixed_sf = containers.Map();

fixed_sf("Width [m]")            = 0.4;
fixed_sf("Diameter [m]")      = 0.9;
fixed_sf("Slip ratio")           = 0.2;
fixed_sf("Velocity [m/s]")       = 5;
fixed_sf("Vehicle weight [kg]")  = 7000;
fixed_sf("Deflection of the wheel [m]")  = 0.002;


yVars = ["Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]"];
labels4 = {"Rigid quadratic","Elastic quadratic","Rigid constant","Elastic constant"};

for y = yVars
    scatterCompare4Models( ...
        TAB_quad_rigida, TAB_quad_flessibile, TAB_semplice_rigid, TAB_semplice_elastic, ...
        "Number of wheel", y, ...
        fixed_qr, fixed_qf, fixed_sr, fixed_sf, ...
        labels4, ...
        'Trend',"quadratic", ...
        'Tol',tolMap, ...
        'CVar',"Deflection of the wheel [m]");
end


%% Comparison of the 4 models varying only slip
% with outputs: Fx Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]

% === RIGID QUADRATIC ===
fixed_qr = containers.Map();

fixed_qr("Width [m]")            = 0.4;
fixed_qr("Diameter [m]")      = 0.9;
fixed_qr("Number of wheel")           = 6;
fixed_qr("Velocity [m/s]")       = 5;
fixed_qr("Vehicle weight [kg]")  = 7000;


% === ELASTIC QUADRATIC ===
fixed_qf = containers.Map();

fixed_qf("Width [m]")            = 0.4;
fixed_qf("Diameter [m]")      = 0.9;
fixed_qf("Number of wheel")           = 6;
fixed_qf("Velocity [m/s]")       = 5;
fixed_qf("Vehicle weight [kg]")  = 7000;


% === SIMPLE – RIGID ===
fixed_sr = containers.Map();

fixed_sr("Width [m]")               = 0.4;
fixed_sr("Diameter [m]")         = 0.9;
fixed_sr("Number of wheel")              = 6;
fixed_sr("Velocity [m/s]")          = 5;
fixed_sr("Vehicle weight [kg]")     = 7000;


% === SIMPLE MODEL (TAB_semplice) ===
fixed_sf = containers.Map();

fixed_sf("Width [m]")            = 0.4;
fixed_sf("Diameter [m]")      = 0.9;
fixed_sf("Number of wheel")           = 6;
fixed_sf("Velocity [m/s]")       = 5;
fixed_sf("Vehicle weight [kg]")  = 7000;
fixed_sf("Deflection of the wheel [m]")  = 0.002;


yVars = ["Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]"];
labels4 = {"Rigid quadratic","Elastic quadratic","Rigid constant","Elastic constant"};

for y = yVars
    scatterCompare4Models( ...
        TAB_quad_rigida, TAB_quad_flessibile, TAB_semplice_rigid, TAB_semplice_elastic, ...
        "Slip ratio", y, ...
        fixed_qr, fixed_qf, fixed_sr, fixed_sf, ...
        labels4, ...
        'Trend',"quadratic", ...
        'Tol',tolMap, ...
        'CVar',"Deflection of the wheel [m]");
end

%% Comparison of the 4 models varying only velocity
% with outputs: Fx Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]

% === RIGID QUADRATIC ===
fixed_qr = containers.Map();

fixed_qr("Width [m]")            = 0.4;
fixed_qr("Diameter [m]")      = 0.9;
fixed_qr("Number of wheel")           = 6;
fixed_qr("Slip ratio")       = 0.2;
fixed_qr("Vehicle weight [kg]")  = 7000;


% === ELASTIC QUADRATIC ===
fixed_qf = containers.Map();

fixed_qf("Width [m]")            = 0.4;
fixed_qf("Diameter [m]")      = 0.9;
fixed_qf("Number of wheel")           = 6;
fixed_qf("Slip ratio")       = 0.2;
fixed_qf("Vehicle weight [kg]")  = 7000;


% === SIMPLE – RIGID ===
fixed_sr = containers.Map();

fixed_sr("Width [m]")               = 0.4;
fixed_sr("Diameter [m]")         = 0.9;
fixed_sr("Number of wheel")              = 6;
fixed_sr("Slip ratio")          = 0.2;
fixed_sr("Vehicle weight [kg]")     = 7000;


% === SIMPLE MODEL (TAB_semplice) ===
fixed_sf = containers.Map();

fixed_sf("Width [m]")            = 0.4;
fixed_sf("Diameter [m]")      = 0.9;
fixed_sf("Number of wheel")           = 6;
fixed_sf("Slip ratio")       = 0.2;
fixed_sf("Vehicle weight [kg]")  = 7000;
fixed_sf("Deflection of the wheel [m]")  = 0.002;


yVars = ["Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]"];
labels4 = {"Rigid quadratic","Elastic quadratic","Rigid constant","Elastic constant"};

for y = yVars
    scatterCompare4Models( ...
        TAB_quad_rigida, TAB_quad_flessibile, TAB_semplice_rigid, TAB_semplice_elastic, ...
        "Velocity [m/s]", y, ...
        fixed_qr, fixed_qf, fixed_sr, fixed_sf, ...
        labels4, ...
        'Trend',"quadratic", ...
        'Tol',tolMap, ...
        'CVar',"Deflection of the wheel [m]");
end

%% Comparison of the 4 models varying only vehicle weight
% with outputs: Fx Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]

% === RIGID QUADRATIC ===
fixed_qr = containers.Map();

fixed_qr("Width [m]")            = 0.4;
fixed_qr("Diameter [m]")      = 0.9;
fixed_qr("Number of wheel")           = 6;
fixed_qr("Velocity [m/s]")       = 5;
fixed_qr("Slip ratio")  = 0.2;


% === ELASTIC QUADRATIC ===
fixed_qf = containers.Map();

fixed_qf("Width [m]")            = 0.4;
fixed_qf("Diameter [m]")      = 0.9;
fixed_qf("Number of wheel")           = 6;
fixed_qf("Velocity [m/s]")       = 5;
fixed_qf("Slip ratio")  = 0.2;


% === SIMPLE – RIGID ===
fixed_sr = containers.Map();

fixed_sr("Width [m]")               = 0.4;
fixed_sr("Diameter [m]")         = 0.9;
fixed_sr("Number of wheel")              = 6;
fixed_sr("Velocity [m/s]")          = 5;
fixed_sr("Slip ratio")     = 0.2;


% === SIMPLE MODEL (TAB_semplice) ===
fixed_sf = containers.Map();

fixed_sf("Width [m]")            = 0.4;
fixed_sf("Diameter [m]")      = 0.9;
fixed_sf("Number of wheel")           = 6;
fixed_sf("Velocity [m/s]")       = 5;
fixed_sf("Slip ratio")  = 0.2;
fixed_sf("Deflection of the wheel [m]")  = 0.002;


yVars = ["Drawbar pull [N]","Total Motion resistance [N]","Drive power [W]","Maximum sinkage [m]"];
labels4 = {"Rigid quadratic","Elastic quadratic","Rigid constant","Elastic constant"};

for y = yVars
    scatterCompare4Models( ...
        TAB_quad_rigida, TAB_quad_flessibile, TAB_semplice_rigid, TAB_semplice_elastic, ...
        "Vehicle weight [kg]", y, ...
        fixed_qr, fixed_qf, fixed_sr, fixed_sf, ...
        labels4, ...
        'Trend',"quadratic", ...
        'Tol',tolMap, ...
        'CVar',"Deflection of the wheel [m]");
end