I need help getting the last part of my code to work. This program is susing the
ID: 2961793 • Letter: I
Question
I need help getting the last part of my code to work. This program is susing the bisection method to find the zero value of the variable 'psi'. That part is done correctly and working. In the second part I need to find the Xi components and Yi components. The equations are correct in the code. What I need help is is storing the values for Xi and Yi as a function of K7. I am having a difficulty storing the values for each iteration. Once that is done I will need to graph it, but I can do that.
my code is as follows:
n = 1;
for k7 = 0.05:0.05:4.0
%define constants
z = [0.16 0.09 0.21 0.13 0.06 0.15 0.20];
k = [3.52 1.92 1.22 0.84 0.43 0.08 k7];
%defines anonymous function for formula to be used for bisection method
bi = @(x) sum((z.*(1-k))./(1+(x.*(k-1))));
%initialize upper and lower bounds
u = 1;
L = 0;
x = (u+L)/2;
tol = 0.00000001;
E = 1;
%bisection method
while E > tol
x = (u+L)/2.0;
if bi(x)*bi(u) < 0
L = x;
else
u = x;
end
E = abs(u-L)/2.0;
end
p(n) = x;
n = n + 1;
end
psi = p(1,n-1);
%disp(psi)
%disp(u)
%disp(L)
n = 1;
for k7 = 0.05:0.05:4.0
z = [0.16 0.09 0.21 0.13 0.06 0.15 0.20];
%anon function for x mole fraction
xfraction = @(psi) z./(1+(psi*(k7 - 1)));
Xi = xfraction(psi);
Yi=Xi.*k7;
Xi(n) = Xi;
Yi(n) = Yi;
n=n+1;
end
plot(x1,k7,y1,k7)
Explanation / Answer
PROGRAM CODE for the above:
clear all
clc
n = 1;
for k7 = 0.05:0.05:4.0
%define constants
z = [0.16 0.09 0.21 0.13 0.06 0.15 0.20];
k = [3.52 1.92 1.22 0.84 0.43 0.08 k7];
%defines anonymous function for formula to be used for bisection method
bi = @(x) sum((z.*(1-k))./(1+(x.*(k-1))));
%initialize upper and lower bounds
u = 1;
L = 0;
x = (u+L)/2;
tol = 0.00000001;
E = 1;
%bisection method
while E > tol
x = (u+L)/2.0;
if bi(x)*bi(u) < 0
L = x;
else
u = x;
end
E = abs(u-L)/2.0;
end
p(n) = x;
n = n + 1;
end
psi = p(1,n-1);
%disp(psi)
%disp(u)
%disp(L)
n = 1;
for k7 = 0.05:0.05:4.0
z = [0.16 0.09 0.21 0.13 0.06 0.15 0.20];
%anon function for x mole fraction
xfraction = @(psi) z./(1+(psi*(k7 - 1)));
Xi = xfraction(psi);
Yi=Xi.*k7;
X1(n,:) = Xi;
Y1(n,:) = Yi;
K77(1,n)=k7;
n=n+1;
end
figure
plot(X1,K77)
title('X1');
figure
plot(Y1,K77)
title('Y1');
figure
plot(X1,K77,Y1,K77)
title('X1 and Y1 as a function of K77');
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.