% Calculate bike power given air and rolling friction
vk = (10:10:50) %km/h
v = vk./3.6;

m = 100
CdA = 0.4
Crr = 0.005
Pb = CdA.*v.^3+Crr*m*g*v

kd = (3*CdA.*v.^3+Crr*m*g*v)./Pb

% Identify Cda and Crr*m*g from data:
v = [10, 20, 30, 40]'
Ps = [30 120 250 500]'

A = [v.^3 v]

xs = A\Ps


vv = 0:1:50;
Psvv = xs(1).*vv.^3+xs(2)*vv;
clf
plot(vv,Psvv)
% plot(vv,Psvv,vv,xs(1).*vv.^3,vv,xs(2)*vv)
hold on
plot(v,Ps,'*')

%disc wheel
Pd = [22 110 220 400]'
xd = A\Pd

Pdvv = xd(1).*vv.^3+xd(2)*vv;
clf
plot(vv,Psvv,vv,Pdvv)
hold on
plot(v,Ps,'*',v,Pd,'*' )






