%% Exponential and Power Law Data
% Atmospheric Pressure and Altitude from https://seattlecentral.edu/qelp/sets/024/024.html
%

A = importdata('AtmosAlt.txt');
x = A(:,1);
y = A(:,2);

plot(x,y,'.','MarkerSize',20)
xlabel('Altitude (km)'), ylabel('Pressure (mb)'), axis tight

%
% Exponential data: y=y_0e^{kx}.
% Linearize: \ln y = \ln y_0+kx.
%

y2 = log(y);
V  = [ x.^0, x ];                 
c  = V\y2               % c(1)=ln y_0, c2 = k

%

y0 = exp(c(1))
f  = @(t) y0*exp(c(2)*t);
hold on
fplot(f,[0 50])
hold off

%
% Size-Velocity Data for River Particles from https://seattlecentral.edu/qelp/sets/004/004.html
%

A = importdata('SizeVel.txt');
x = A(:,1);
y = A(:,2);

plot(x,y,'.','MarkerSize',20)
xlabel('Velocity (m/s)'), ylabel('Size (mm)'), axis tight

%
% Power Law Data: y=ax^k
% Linearize: \ln y = \ln a+k\ln x
%

x2 = log(x);
y2 = log(y);
V  = [ x2.^0, x2 ];                 
c  = V\y2               % c(1)=ln a, c2 = k

%

a = exp(c(1));
k = c(2);
f  = @(t) a*t.^k;
hold on
fplot(f,[0 180])
hold off