close all
clear all

rho = 1025;
g = 9.81

m = 362;  %kg
disp = 372/rho;  %m^3
Cd = 1.0;

A = 1.05;  %Horizontally projected area

Vx = 0:.1:2;   %m/s
Fx = .5*Cd*rho*A*Vx.^2;

figure('Position',[1000 307 1042 1191],'PaperPositionMode','manual','PaperType','usletter','PaperPosition',[0 0 8.5 11]);
subplot(2,1,1)
plot(Vx,Fx/4.45);
set(gca,'FontSize',12);
xlabel('Horizontal Speed (m/s)');
ylabel('Force (lbs)');
title('Force at pivot point versus horizontal speed');

Vx = [.1 .8 1.4 2];  %m/s
Fx = .5*Cd*rho*A*Vx.^2;



KB = 26.3*.0254;  %m
KG = 15.7*.0254;  %m

KP = (26.3)*.0254;  %m

KE_Error = -5:.25:5;  %Percentage
KE = (.66661/.0254+KE_Error)*.0254;  %m

Fy = [0]*4.45;  %N

Fb = rho*g*disp;

Fg = -m*g;


    for j = 1:length(Vx)
        leg_str{j} = ['Horizontal Speed = ' num2str(Vx(j)) ' m/s']
        %Fy = Fx(j);  %45 degrees
      for i = 1:length(KE) 
    th(i,j) = Fx(j)*(KE(i)-KP)./(-Fb*(KB-KP)-Fg*(KG-KP)-Fy*(KE(i)-KP));
    end
end

%for i = 1:length(KP)
%    th(i) = Fx*(KE-KP(i))./(-Fb*(KB-KP(i))-Fg*(KG-KP(i))+Fy*(KE-KP(i)));
%end

%plot(Fx/4.45,th*180/pi);

leg_str{2} = [leg_str{2} '   (Del Mar Maximum)'];
leg_str{3} = [leg_str{3} '   (CCE Maximum)'];


subplot(2,1,2)
set(gca,'FontSize',12);
plot(KE_Error,th*180/pi);
legend(leg_str);
xlabel('Error in Estimate of center of drag (or pivot point) in inches')
ylabel('Resulting Pitch Angle (degrees)');
title(['ESP in Frame:      Mass = ' num2str(m) ' kg         Disp. = ' num2str(disp*rho,3) ' kg SW         CG-CB = ' num2str((KG-KB)/.0254,3) ' inches']);
print('-dpdf','StaticPitchAnalysis')


