0% found this document useful (0 votes)
20 views

Answer To Exercises Anonymous

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Answer To Exercises Anonymous

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

SW 9

SW 10
SW 11
Solution with MATLAB
>> S0 = [100;0.20;0];
>> L0 = [452/3;0;1];
>> S1 = [0;1/300;0.33];
>> UNDERFLOW = @(x) 1/3-x;
>> r_leachcounter2(S0,L0,S1,3,UNDERFLOW);
% Objective is already reached with N = 3.

Delta is found above the triangle.


The ternary diagram

Zoomed in
SW 12
Solution with MATLAB
>> S0 = [20;0.10;0.05];
>> L0 = [50.64;0;1];
>> S1 = [0;0.04;34]./51.04;
>> UNDERFLOW = @(x) 2*(1-x)/3;
>> r_leachcounter2(S0,L0,S1,3,UNDERFLOW);
% N is increased until the objective is reached.
% In this case, it is reached when N = 10.
>> r_leachcounter2(S0,L0,S1,10,UNDERFLOW);

DELTA is found way below the triangle.


The ternary diagram. The points are concentrated and look
indistinguishable.

Zoomed in.

The script was created assuming that the DELTA is above (and thus, line is drawn from the underflow
instead of from overflow).
SW 13
Experimental 𝑁 vs. 𝑦𝐴 is fitted using a cubic polynomial (R is very close to 1)
function TAB = r_leachcounter2(S0,L0,S1,N,UFfunc)
%LEACHCOUNTER2 Countercurrent Multistage Leaching
% Detailed explanation goes here
%Solution is for unknown number of stages
%Leave S1(1) = 0.

%syms x y
OFfunc = @(x) 1 - x;

figure
hold on

XX = linspace(0,1,100);
Orang = [255 165 0]./255;
Reddo = [255 0 0]./255;
Bru = [0 0 255]./255;

n = length(S0);

S0 = r_verticalize(S0);
L0 = r_verticalize(L0);
S1 = r_verticalize(S1);

if n==3 %xyz only


%Calculate z
C = getColor(1,N+1);
S0(end+1) = 1-S0(2)-S0(3);
L0(end+1) = 1-L0(2)-L0(3);
S1(end+1) = 1-S1(2)-S1(3);
plotPoint(S0,C) %=====================
plotPoint(L0,C) %=====================
plotPoint(S1,C) %=====================

MAT = [S0,L0];

Sfr = S0(1)+L0(1); %flowrate S


Scomp = (S0(2:4).*S0(1) + L0(2:4).*L0(1))./Sfr; %composition of S
S = [Sfr;Scomp];

MAT(:,3) = S;
plotPoint(S,[0 0 0]) %=====================
drawLine(S0,L0,Reddo) %=====================

%Graphically obtain LN
TLf0 = r_polyfits([S1(2) S(2)],[S1(3) S(3)],1,'func','off');
plot(XX,TLf0(XX),"--","Color",Reddo) %=====================
[xLN,yLN] = intersectLines(TLf0,OFfunc);
zLN = 1 - xLN - yLN;

LN = [0;xLN;yLN;zLN];

%ILAR
S1(1) = S(1)*(S(2)-LN(2))/(S1(2)-LN(2));
LN(1) = S(1)-S1(1);

MAT(:,4:5) = [S1,LN];
plotPoint(LN,C) %=====================
varNames = ["S_0","L_0","S","S_{1_0}","L_{"+string(N)+"}"];

for i=1:N
Sc = 6+2*(i-1);
C = getColor(i+1,N+1);

if i==1

%Get DELTA
DL1 = getrLine(L0,S1);
DL2 = getrLine(LN,S0);

[xDELTA,yDELTA] = intersectLines(DL1,DL2);
frDELTA = L0(1)-S1(1);
zDELTA = 1 - xDELTA - yDELTA;
dx_ = [xDELTA;yDELTA;zDELTA;1].*frDELTA;

DELTA = [0;xDELTA;yDELTA;0];
plotPoint(DELTA,Orang) %=====================
drawLine(S1,DELTA,Orang) %=====================
drawLine(S0,DELTA,Orang) %=====================

MAT(:,Sc) = DELTA;

%Get SN from LN
O = [0;0;0;0];
OLN = getrLine(O,LN);
plotPoint(O,[0 0 0]) %=====================
drawLine(O,LN,Bru) %=====================

[xSN,ySN] = intersectLines(OLN,UFfunc);
zSN = 1 - xSN - ySN;
SN = [0;xSN;ySN;zSN];

MAT(:,Sc+1) = SN;
plotPoint(SN,C); %=====================

varNames = [varNames,"DELTA","S_{"+string(N)+"}"];
SNprev = SN;

%CHECKING
% disp("=================================================")
% A = [[LN(2:4);1],-[S0(2:4);1]]
% A \ dx_
else
%Get L_{N-(i-1)} from LN
LSD = getrLine(SNprev,DELTA);
[xLnow,yLnow] = intersectLines(LSD,OFfunc);
drawLine(SNprev,DELTA,Orang) %=====================
zLnow = 1 - xLnow - yLnow;

Lnow = [0;xLnow;yLnow;zLnow];

MAT(:,Sc) = Lnow;
plotPoint(Lnow,C); %=====================

%Get S_{N-(i-1)} from L_{N-(i-1)}


OLnow = getrLine(O,Lnow);
[xSnow,ySnow] = intersectLines(OLnow,UFfunc);
drawLine(O,Lnow,Bru) %=====================
zSnow = 1 - xSnow - ySnow;

Snow = [0;xSnow;ySnow;zSnow];

MAT(:,Sc+1) = Snow;
plotPoint(Snow,C) %=====================

%Get flowrate of SNprev and Lnow using ILAR


frSnprev = -frDELTA * (xDELTA-Lnow(2))/(SNprev(2)-Lnow(2));
frLnow = frDELTA + frSnprev;

MAT(1,Sc-1) = frSnprev;
MAT(1,Sc) = frLnow;

%If final stage, get flowrate of Snow.


if i==N
%ILAR again
% frSnow = S(1)*(S(2)-LN(2))/(Snow(2)-LN(2));
% MAT(1,Sc+1) = frSnow;
% LN(1) = S(1) - frSnow;
% MAT(:,Sc+2) = LN;

frSnow = S(1) - LN(1);


MAT(1,Sc+1) = frSnow;

varNames = [varNames,"L_{"+string(N-(i-1))+"}","S_{"+string(N-(i-1))+"}"];
else
varNames = [varNames,"L_{"+string(N-(i-1))+"}","S_{"+string(N-(i-1))+"}"];
end

SNprev = Snow;

end

end

%Tabulate

TA = table(convertStringsToChars(string(varNames.')));

TBd = table(round(MAT.',4)); %for display


TB = table(MAT.');

TAB = splitvars(TB);
TABd = splitvars(TBd);

TAB = [TA,TAB];
TABd = [TA,TABd];

TAB.Var1 = categorical(TAB.Var1);
TAB.Properties.VariableNames = ["Stream","Flowrate","x","y","z"];

TABd.Var1 = categorical(TABd.Var1);
TABd.Properties.VariableNames = ["Stream","Flowrate","x","y","z"];

disp(TABd)
%Plot remaining stuff
plot(XX,OFfunc(XX),"-","Color",[0 128 0]./255,"MarkerSize",15)
UFcurve = r_removePoints([XX.',UFfunc(XX.')],[UFfunc(XX.')],@(x) x<0);
plot(UFcurve(:,1),UFcurve(:,2),"-","Color",[0 128 0]./255,"MarkerSize",15)
line([0 0],[0 1],"LineStyle","-","Color",[0 0 0],"MarkerSize",10)
line([0 1],[0 0],"LineStyle","-","Color",[0 0 0],"MarkerSize",10)
boundX = [min(0,xDELTA) max(1,xDELTA)].*1.1;
boundY = [min(0,yDELTA) max(1,yDELTA)].*1.1;
xlim(boundX)
ylim(boundY)

%Add text descriptions


for j=1:numel(varNames)
text(TAB{j,3}+0.0001,TAB{j,4}+0.0001,TAB{j,1},'FontSize',15)
end

end

end

function fy = getrLine(Sx,Lx)
fy = r_polyfits([Sx(2) Lx(2)],[Sx(3) Lx(3)],1,'func','off');
end

function [x,y] = intersectLines(f1,f2)


opts = optimoptions("fsolve","MaxIterations",2000,"OptimalityTolerance",1e-20,"FunctionTolerance",1e-
20,"StepTolerance",1e-20,"Algorithm","trust-region","Display","none");
x = fsolve(@(x) f1(x)-f2(x),0,opts);
y = f2(x);
end

function plotPoint(Sx,C,varargin)
plot(Sx(2),Sx(3),'.',"Color",C,"MarkerSize",20)
end

function drawLine(Sx,Lx,C)
line([Sx(2) Lx(2)],[Sx(3) Lx(3)],"Color",C,"LineStyle","--")
end

function C = getColor(i,N)
Blue = [0 0 255]/255; %start at blue
Red = [255 0 0]/255; %gets redder as it gets to the end

C = Red*(i/N)+Blue*(N-i)/N;
end
function Vv = r_verticalize(Vh)
%VERTICALIZE Vertical vector
% Vv = r_verticalize(Vh), turns the vector Vh into a vertical
% vector Vv only if Vh is horizontal.

[r,c] = size(Vh);

if (r==1)&&(c>1)
Vv = Vh.';
else
Vv = Vh;
end

end

function fy = r_polyfits(X,Y,N,varargin)
%POLYFITS Polynomial Fit-Symbolic
% fy = r_polyfits(X,Y,N), obtains the symbolic equation of the fitted
% polynomial
% fy = r_polyfits(X,Y,N,'func'), obtains fy as a matlab function.

%Change this if you want.


precision = 14;

syms x y

C = polyfit(X,Y,N);

%Comment the next line if you don't want rounding.


C = round(C,precision);

Xs = x.^(N:-1:0);
Ys = sum(Xs.*C);

fy = y == Ys;

if numel(varargin)>=1 && (varargin{1} == "func")


fy = matlabFunction(rhs(fy));
end

if numel(varargin)>=2 && varargin{2} == "off"

else
fymf = matlabFunction(rhs(fy));
disp("Residuals:")
disp(fymf(X)-Y)
end
end
function M = r_removePoints(varargin)
%REMOVEPOINTS Conditionally Remove Points
% M = r_removePoints(M,f), evaluates f for every value in the row of
% M. If f returns true on any value in a row, removes the whole row of M.
% M = r_removePoints(M,N,f), evaluates f on N instead.

switch (numel(varargin))
case 2
M = varargin{1};
N = M;
f = varargin{2};
case 3
M = varargin{1};
N = varargin{2};
f = varargin{3};
otherwise
disp("Error, invalid number of arguments!")
return
end

[r,~] = size(M);

for i=r:-1:1
F = f(N(i,:));

if sum(F)>=1
M(i,:) = [];
end
end
end

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy