function y = drilling4u(u)
%Function that calculates drilling model equations.
%Run main4u.m
%DEH - 2010

global db dstring kc WOB RPM qmud pc

y = zeros(9,1);

WOB = u(1);
RPM = u(2);
qmud = u(3);
pc = u(4);

x0 = [15;1;460];
res = fsolve(@drillsolve4u,x0);
y(1) = res(1); %ROP
y(4) = res(2); %Cuttings fraction
y(5) = res(3); %Mud flow
F = u(1)/db*kc*db^2*pi/4; %Force, N, function of WOB and formation strength
y(2) = F*dstring/2000; %Torque, kNm.
y(3) = y(2)*2*pi*u(2)/60; %Power, kW
y(6) = u(1);
y(7) = u(2);
y(8) = u(3);
y(9) = u(4);