clear all
close all

filenm = 'AirTest2.txt';

fid = fopen(filenm);

C = textscan(fid,'%f %f %f %c');

fclose(fid);

t = C{1};
Spd = C{2};
Torque= C{3};
Dir = C{4};

clear C;


first = 285;
last = length(t);
t = t(first:last);
Spd = Spd(first:last);

t = t-t(1);



w0 = Spd(1);

I = .0017;  %kg-m^2;
A = .00000004;
B = .0002;
a = A/I;
b = B/I;

epsilon = 0.000001;
dL = epsilon*ones(2,1);
while(norm(dL) > epsilon)

w = omega(a,b,t,w0);


dB = Spd-w;

dw_da = domega_da(a,b,t,w0);
dw_db = domega_db(a,b,t,w0);
AA = [dw_da dw_db];

aa = AA'*AA;
bb = AA'*dB;

dL = aa\bb;

a = a+dL(1);
b = b+dL(2);
end


figure
plot(t,Spd,t,w);


xlabel('Time (s)');
ylabel('Speed (rpm)');
title(filenm);

I
A = a*I
B = b*I


Nc = 10;
Ac = .25*pi*(1*.0254)^2;
rho = 1.2;
dp = 8*.0254;

Cd = 4*A*60^2/(Nc*rho*Ac*pi^2*dp^3)







print('-depsc2',[filenm '.ps'])


