Results: Name: Nur Aneesa Binti Abdul Halim STUDENT NO: 44624343 Matlab Week 9

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

NAME: NUR ANEESA BINTI ABDUL HALIM

STUDENT NO: 44624343

MATLAB WEEK 9

RESULTS
x0=[1e-3 ; 1e-4];
Local minimum possible.
lsqnonlin stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
<stopping criteria details>
klaA = 0.000675 (CI: 0.000618 - 0.000731)
klaB = 0.000585 (CI: 0.000522 - 0.000649)

Observation:
- The accuracy for the initial guess is high because the confidence interval is within the range.

x0=[1e-3 ; 9];
Local minimum possible.
lsqnonlin stopped because the size of the current step is less than
the default value of the step size tolerance.
<stopping criteria details>
klaA = 0.000687 (CI: 0.000367 - 0.001007)
klaB = 8.605872 (CI: 8.213879 - 8.997865)

Observation:
- The accuracy of initial guess is low due to high range of confidence interval
RESULTS

Iterations are 4 and function evaluations are 15. The reasons there are different due to
reannealing step that includes gradient estimation. That increases the function count over
iteration count. Besides that, there is an initial error-check that evaluates the objective
function before any iterations take place.
klaA = 0.000675 (CI: 0.000618 - 0.000731)
klaB = 0.000585 (CI: 0.000522 - 0.000649)

RESULTS
Mean residue -0.0007
Normalised RMSE 0.0538
Relative RMSE 0.0573
R-squared 0.9462
Adj R-squared 0.9434

Comment: There calibration process adjusted the R-squared and increases the relative RMSE.
DRIVER
%Driver to evaluate a liquid liquid extractor model
%This driver sets initial conditions, runs the solver,
%and plots the results.
clear all
close all

% read in data
load data.csv
tdata=data(:,1); % time steps at which we have data

%set initial conditions. Zero in the solvent phase and equal to input in
the liquid phase.
% State variables are: Cas Cbs Cal Cbl
y0=[0,0,1,0.75];

%solve the model, by calling ODE45 with calibrated parameters


% Note that we specify the time values of the experimental data as our
% tspan parameter to ode45
% Therefore the time vectors for both the simulated and experimental data
% are identical so no interpolation is needed (t=tdata)
par=[0.000675 ;0.000585]; % !!! These will need updating with your
optimised values !!!
[t,y]=ode45(@(t,y)extractif(t,y,par),tdata,y0);

%Specify data sets to analyse


CALmodel=y(:,3);
CALdata=data(:,2);
CBLmodel=y(:,4);
CBLdata=data(:,3);

%Plot the data and model over time to assess the calibration
subplot(2,2,1);
plot(t,CALmodel,'k-',t,CALdata,'k+',t,CBLmodel,'k-',t,CBLdata,'k*');
legend('C_{AL} model', 'C_{AL}','C_{BL} model', 'C_{BL}');
xlabel('time, s');
ylabel(' concentration, kg m^{-3}');
title('Calibration data vs calibrated model');

%calculate and plot residuals


subplot(2,2,2);
eA=CALdata-CALmodel;
eB=CBLdata-CBLmodel;
plot(t,eA,'k+',t,eB,'k*');
xlabel('time, s');
ylabel('\epsilon=y_{i}-y_{mi}');
legend('C_{AL}','C_{BL}');

%Plot measured vs predicted for data CAL


subplot(2,2,3);
plot(CALdata,CALmodel,'k+');
hold on;
xmin=min(min(CALmodel),min(CALdata));
xmax=max(max(CALmodel),max(CALdata));
plot([xmin xmax],[xmin,xmax],'k-'); %this generates a y=x line
xlabel('measured C_{AL}, kg m^{-3}');
ylabel('predicted C_{AL}, kg m^{-3}');

%Plot measured vs predicted for data CBL


subplot(2,2,4);
plot(CBLdata,CBLmodel,'k*');
hold on;
xmin=min(min(CBLmodel),min(CBLdata));
xmax=max(max(CBLmodel),max(CBLdata));
plot([xmin xmax],[xmin,xmax],'k-'); %this generates a y=x line
xlabel('measured C_{BL}, kg m^{-3}');
ylabel('predicted C_{BL}, kg m^{-3}');

% Quantify error in calibration


residuals = [eA;eB];
ydata = [CALdata;CBLdata];
ymodel = [CALmodel;CBLmodel];
nresiduals=length(residuals);
meanResidual = mean(residuals);
RMSE = sqrt(mean(residuals.^2));
NormalisedRMSE = RMSE/(max(ydata)-min(ydata));
RelativeErr = (ydata-ymodel)./ydata;
RelativeRMSE=sqrt(mean(RelativeErr.^2));
SSres=sum(residuals.^2);
SStot=sum((ydata-mean(ydata)).^2);
Rsquared=1-SSres/SStot;
adjRsquared=1-(1-Rsquared)*(nresiduals-1)/(nresiduals-length(par)-1);

fprintf('Mean residue %7.4f\n',meanResidual);


fprintf('Normalised RMSE %7.4f\n',NormalisedRMSE);
fprintf('Relative RMSE %7.4f\n',RelativeRMSE);
fprintf('R-squared %7.4f\n',Rsquared);
fprintf('Adj R-squared %7.4f\n',adjRsquared);
RESULTS
The result is 80%. The model is valid due to the pattern of more randomly distributed graph.

FUNCTION
function f=extractif(t,y,par)
%Code to describe liquid-liquid extractor
%Intensive implementation with transfer coefficients as parameters

%local variable assignment


Cas = y(1); %kg
Cbs = y(2); %kg
Cal = y(3); %kg
Cbl = y(4); %kg

%extra parameters (passed via anonymous function mechanism)


kla = par(1);
klb = par(2);

%Parameters and constants


%kla = 6.944E-4; %m3 s-1
%klb = 5.555E-4; %m3 s-1
Vs = 10; %m3
Vl = 5; %m3

%Inputs and disturbances


F1 = 0.0037; %m3 s-1
F3 = 0.0005; %m3 s-1
Ca1 = 0.5401; %kg m-3
Cb1 = 0.4376; %kg m-3
Ca3 = 0.2299; %kg m-3
Cb3 = 0.1562; %kg m-3
%Constitutive
Cstaral = 1.25 * Cas - 0.2* Cbs;
Cstarbl = Cbs + 0.5*Cas^2;

%Conservation
f(1) = F1/Vs * (Ca1 - Cas) - kla * (Cstaral-Cal )* Vl/Vs;
f(2) = F1/Vs * (Cb1 - Cbs) - klb * (Cstarbl-Cbl )* Vl/Vs;
f(3) = F3/Vl * (Ca3 - Cal) + kla * (Cstaral-Cal );
f(4) = F3/Vl * (Cb3 - Cbl) + klb * (Cstarbl-Cbl );

f=f';

DRIVER
%Driver to evaluate a liquid liquid extractor model
%This driver sets initial conditions, runs the solver,
%and plots the results.
clear all
close all

% read in data
load data.csv
tdata=data(:,4); % time steps at which we have data

%set initial conditions. Zero in the solvent phase and equal to input in
the liquid phase.
% State variables are: Cas Cbs Cal Cbl
y0=[0.2299,0.1562,0.5401,0.4376];
%solve the model, by calling ODE45 with calibrated parameters
% Note that we specify the time values of the experimental data as our
% tspan parameter to ode45
% Therefore the time vectors for both the simulated and experimental data
% are identical so no interpolation is needed (t=tdata)
par=[0.000675 ;0.000585]; % !!! These will need updating with your
optimised values !!!
[t,y]=ode45(@(t,y)extractif(t,y,par),tdata,y0);

%Specify data sets to analyse


CALmodel=y(:,3);
CALdata=data(:,5);
CBLmodel=y(:,4);
CBLdata=data(:,6);

%Plot the data and model over time to assess the calibration
subplot(2,2,1);
plot(t,CALmodel,'k-',t,CALdata,'k+',t,CBLmodel,'k-',t,CBLdata,'k*');
legend('C_{AL} model', 'C_{AL}','C_{BL} model', 'C_{BL}');
xlabel('time, s');
ylabel(' concentration, kg m^{-3}');
title('Calibration data vs calibrated model');
%calculate and plot residuals
subplot(2,2,2);
eA=CALdata-CALmodel;
eB=CBLdata-CBLmodel;
plot(t,eA,'k+',t,eB,'k*');
xlabel('time, s');
ylabel('\epsilon=y_{i}-y_{mi}');
legend('C_{AL}','C_{BL}');

%Plot measured vs predicted for data CAL


subplot(2,2,3);
plot(CALdata,CALmodel,'k+');
hold on;
xmin=min(min(CALmodel),min(CALdata));
xmax=max(max(CALmodel),max(CALdata));
plot([xmin xmax],[xmin,xmax],'k-'); %this generates a y=x line
xlabel('measured C_{AL}, kg m^{-3}');
ylabel('predicted C_{AL}, kg m^{-3}');

%Plot measured vs predicted for data CBL


subplot(2,2,4);
plot(CBLdata,CBLmodel,'k*');
hold on;
xmin=min(min(CBLmodel),min(CBLdata));
xmax=max(max(CBLmodel),max(CBLdata));
plot([xmin xmax],[xmin,xmax],'k-'); %this generates a y=x line
xlabel('measured C_{BL}, kg m^{-3}');
ylabel('predicted C_{BL}, kg m^{-3}');

% Quantify error in calibration


residuals = [eA;eB];
ydata = [CALdata;CBLdata];
ymodel = [CALmodel;CBLmodel];
nresiduals=length(residuals);
meanResidual = mean(residuals);
RMSE = sqrt(mean(residuals.^2));
NormalisedRMSE = RMSE/(max(ydata)-min(ydata));
RelativeErr = (ydata-ymodel)./ydata;
RelativeRMSE=sqrt(mean(RelativeErr.^2));
SSres=sum(residuals.^2);
SStot=sum((ydata-mean(ydata)).^2);
Rsquared=1-SSres/SStot;
adjRsquared=1-(1-Rsquared)*(nresiduals-1)/(nresiduals-length(par)-1);

fprintf('Mean residue %7.4f\n',meanResidual);


fprintf('Normalised RMSE %7.4f\n',NormalisedRMSE);
fprintf('Relative RMSE %7.4f\n',RelativeRMSE);
fprintf('R-squared %7.4f\n',Rsquared);
fprintf('Adj R-squared %7.4f\n',adjRsquared);
The function files didn’t change.

RESULTS
It shows the there is big difference between Cal and Cbl against time when the parameters is
modified.

DRIVER
%Driver to evaluate a liquid-liquid extractor model
%This driver sets initial conditions, runs the solver,
%and plots the results.
clear all
close all

% read in data
load data.csv
tdata=data(:,1); % time steps at which we have data

%set initial conditions. Zero in the solvent phase and equal to input in
the liquid phase.
% State variables are: Cas Cbs Cal Cbl
klA = 0.000675;
klB = 0.000585;
y0=[0,0,1,0.75];

%solve the model, by calling ODE45 with calibrated parameters


% Note that we specify the time values of the experimental data as our
% tspan parameter to ode45
% Therefore the time vectors for both the simulated and experimental data
% are identical so no interpolation is needed (t=tdata)
par=[klA , klB]; % !!! These will need updating with your optimised values
!!!
[t1,y1]=ode45(@(t,y)extractif(t,y,par),tdata,y0);

par=[klA , klB*1.2]; % !!! These will need updating with your optimised
values !!!
[t2,y2]=ode45(@(t,y)extractif(t,y,par),tdata,y0);

par=[klA , klB*0.8]; % !!! These will need updating with your optimised
values !!!
[t3,y3]=ode45(@(t,y)extractif(t,y,par),tdata,y0);

par=[klA*1.2 , klB]; % !!! These will need updating with your optimised
values !!!
[t4,y4]=ode45(@(t,y)extractif(t,y,par),tdata,y0);

par=[klA*0.8, klB]; % !!! These will need updating with your optimised
values !!!
[t5,y5]=ode45(@(t,y)extractif(t,y,par),tdata,y0);

f1=(y1-y2)./y1;
subplot(2,2,1),(plot(t1,f1(:,3:4)))
title('Cal and Cbl vs time'),xlabel('time'),ylabel('Cal and Cbl')
f2=(y1-y3)./y1;
subplot(2,2,2),plot(t1,f2(:,3:4))
title('Cal and Cbl vs time'),xlabel('time'),ylabel('Cal and Cbl')
f3=(y1-y4)./y1;
subplot(2,2,3),plot(t1,f3(:,3:4))
title('Cal and Cbl vs time'),xlabel('time'),ylabel('Cal and Cbl')
f4=(y1-y5)./y1;
subplot(2,2,4),plot(t1,f4(:,3:4))
title('Cal and Cbl vs time'),xlabel('time'),ylabel('Cal and Cbl')

You might also like