taredata=readmatrix('ATP_yaw0_pitchtare_clean_elev_down.csv');
taredata=taredata(1:12,:);
yawM5=readmatrix('ATP_yawM5_pitchsweep_clean_elev_down.csv')-taredata;
yawM10=readmatrix('ATP_yawM10_pitchsweep_clean_elev_down.csv')-taredata;
yawM15=readmatrix('ATP_yawM15_pitchsweep_clean_elev_down.csv')-taredata;
yaw0=readmatrix('ATP_yaw0_pitchsweep_clean_elev_down.csv')-taredata;
yaw5=readmatrix('ATP_yaw5_pitchsweep_clean_elev_down.csv')-taredata;
yaw10=readmatrix('ATP_yaw10_pitchsweep_clean_elev_down.csv')-taredata;
yaw15=readmatrix('ATP_yaw15_pitchsweep_clean_elev_down.csv')-taredata;
tare_forces=taredata(2:12,6:11);
yawM5_forces=yawM5(2:12,6:11);
yawM10_forces=yawM10(2:12,6:11);
yawM15_forces=yawM15(2:12,6:11);
yaw0_forces=yaw0(2:12,6:11);
yaw5_forces=yaw5(2:12,6:11);
yaw10_forces=yaw10(2:12,6:11);
yaw15_forces=yaw15(2:12,6:11);
alpha_all=[yawM15(2:12, 12), yawM10(2:12, 12), yawM5(2:12, 12), yaw0(2:12, 12), yaw5(2:12, 12), yaw10(2:12, 12), yaw15(2:12, 12)]
beta_all =[yawM15(2:12, 13), yawM10(2:12, 13), yawM5(2:12, 13), yaw0(2:12, 13), yaw5(2:12, 13), yaw10(2:12, 13), yaw15(2:12, 13)]
fx_all=[yawM15_forces(:,2), yawM10_forces(:,2), yawM5_forces(:,2), yaw0_forces(:,2), yaw5_forces(:,2), yaw10_forces(:,2), yaw15_forces(:,2)]
fy_all=[yawM15_forces(:,3), yawM10_forces(:,3), yawM5_forces(:,3), yaw0_forces(:,3), yaw5_forces(:,3), yaw10_forces(:,3), yaw15_forces(:,3)]
fz_all=[yawM15_forces(:,1), yawM10_forces(:,1), yawM5_forces(:,1), yaw0_forces(:,1), yaw5_forces(:,1), yaw10_forces(:,1), yaw15_forces(:,1)]
D2=[((-Xa_all).*cos(beta_all).*cos(alpha_all))-((Ya_all).*sin(beta_all))-((Za_all).*cos(beta_all).*sin(alpha_all))]
S2=[((Xa_all).*sin(beta_all).*cos(alpha_all))-((Ya_all).*cos(beta_all))+((Za_all).*sin(beta_all).*sin(alpha_all))]
L2=[((Xa_all).*sin(alpha_all))-((Za_all).*cos(alpha_all))]
q_inf2 = [yawM5(2:12,3), yawM10(2:12,3), yawM15(2:12,3), yaw0(2:12,3), yaw5(2:12,3), yaw10(2:12,3), yaw15(2:12,3)]
alpha_vec = [-15 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 15];
p = polyfit(alpha_vec, CL_mean, 1);
alpha_plot = linspace(-15, 15, 1000);
CL_parabola = polyval(p, alpha_plot);
plot(alpha_plot, CL_parabola);
xlabel('Angle of Attack (degrees)');
ylabel('Lift Coefficient (CL)');
title('Linear Fit of Lift Coefficient vs Angle of Attack');
saveas(gcf, 'figure.png')