clear all
close all
addpath(genpath('/Users/Mau/Documents/MATLABhelp_new'));

% Efficiency of the pump for SN29

Ppsi=[0;
0;
100;
100;
500;
500;
1000;
1000;
1500;
1500];

psi2dbar=0.689476;

P=psi2dbar*Ppsi; % in dbar

V=[11.92;
    11.92;
    11.90;
    11.90;
    11.82;
    11.82;
    11.73;
    11.73;
    11.63;
    11.62]; % in Volts
    
I=[335*0.001;
    350*0.001;
    400*0.001;
    420*0.001;
    775*0.001;
    760*0.001;
    1.19;
    1.21;
    1.63;
    1.65]; % in Ampere

time=[23;
    23;
    24;
    24;
    25;
    25;
    27;
    27;
    30;
    30];
    
       
E=V.*I.*time; %

[S,b,r,pval]=regresion(P,E,1); % uses some neural network toolbox function (mse.m)
% for error estimation
xlabel('P [dbar]')
ylabel('E [J]');

% to double check:
X = [ones(length(P),1) P];
C = X\E;

% coefficients are in units of E/P, i.e. J/dbar

% dividing by volume of oil pumped
% 30cc=30*10^(-6) m^3
vol=30*10^(-6);

Jo=b./vol
J=S/vol