Need help in generating plot in while loop for Buckley Leverett code.

Hello, I'm trying to develop a code for the Buckley Leverett equation. I used a while loop to find the tangent point between the curve and tangent line by equating them to one and then subtracting one. The program is computing the correct values, however, it is not able to plot the graph (S-curve with a tangent line to it). A plot pops up with correct axis values but there is no graph. I'm assuming it's because it's graphing only one point because the while loop keeps iterating over it. I already tried hold on, and drawnow, but it was futile. I have included the code below. Any suggestions and thoughts are more than welcomed, thank you.
%Buckely Leverett Plot
clear all
clc
hold on
W=500; %ft
T=25; %ft
L= 1000; %ft
Por =0.18;
Permb= 50; %md base permeability
Sor=0.3;
Viscw= 1 %cp water viscosity
ViscO= 1.62 ; %cp
qi = 200; %B/D
Swi=0.3
Sw =.4
Swd=(Sw-Swi)/(1-Sor-Swi)
Krw= 0.248*Swd.^2.33
Kro=0.402*(1-Swd).^(2.06)
A=Viscw*Kro
B=ViscO*Krw
C= A/B
fw = 1/(1+((Viscw*Kro)/(ViscO*Krw)))+.1
fw2 = 1/(1+((Viscw*Kro)/(ViscO*Krw)))
% Slope1 = (fw - 0)/(Sw-Swi)
% Slope2 = (fw-fw2)/.0001
%fw= 1/(1+((Viscw*Kro)./(ViscO*Krw)))
while (fw/(Sw-Swi))/((fw-fw2)/.00001) - 1 <= .0001
%output(fw)
Slope1 = (fw - 0)/(Sw-Swi)
Slope2 = (fw-fw2)/.0001
Sw = Sw+.0001
Sw2 = Sw-.0001
Swd=(Sw-Swi)/(1-Sor-Swi);
Swd2 = (Sw2-Swi)/(1-Sor-Swi);
Krw= 0.248*Swd^2.33
Krw2= 0.248*Swd2^2.33;
Kro=0.402*(1-Swd)^(2.06)
Kro2=0.402*(1-Swd2)^(2.06);
fw= 1/(1+((Viscw*Kro)/(ViscO*Krw)));
fw2= 1/(1+((Viscw*Kro2)/(ViscO*Krw2)));
plot(Sw,fw,'r-')
drawnow
end

Answers (1)

Replace
plot(Sw,fw,'r-')
with
plot(Sw,fw,'.r')

3 Comments

And the better code would be:
%Buckely Leverett Plot
clear all
clc
W=500; %ft
T=25; %ft
L= 1000; %ft
Por =0.18;
Permb= 50; %md base permeability
Sor=0.3;
Viscw= 1 ; %cp water viscosity
ViscO= 1.62 ; %cp
qi = 200; %B/D
Swi=0.3 ;
Sw =.4 ;
Swd=(Sw-Swi)/(1-Sor-Swi) ;
Krw= 0.248*Swd.^2.33 ;
Kro=0.402*(1-Swd).^(2.06) ;
A=Viscw*Kro ;
B=ViscO*Krw ;
C= A/B ;
fw = 1/(+((Viscw*Kro)/(ViscO*Krw)))+.1 ;
fw2 = 1/(1+((Viscw*Kro)/(ViscO*Krw))) ;
% Slope1 = (fw - 0)/(Sw-Swi)
% Slope2 = (fw-fw2)/.0001
%fw= 1/(1+((Viscw*Kro)./(ViscO*Krw)))
count = 0 ;
x = [] ; y = [] ;
while (fw/(Sw-Swi))/((fw-fw2)/.00001) - 1 <= .0001
count = count+1 ;
%output(fw)
Slope1 = (fw - 0)/(Sw-Swi) ;
Slope2 = (fw-fw2)/.0001 ;
Sw = Sw+.0001 ;
Sw2 = Sw-.0001 ;
Swd=(Sw-Swi)/(1-Sor-Swi);
Swd2 = (Sw2-Swi)/(1-Sor-Swi);
Krw= 0.248*Swd^2.33 ;
Krw2= 0.248*Swd2^2.33;
Kro=0.402*(1-Swd)^(2.06) ;
Kro2=0.402*(1-Swd2)^(2.06);
fw= 1/(1+((Viscw*Kro)/(ViscO*Krw)));
fw2= 1/(1+((Viscw*Kro2)/(ViscO*Krw2)));
x(count) = Sw ;
y(count) = fw ;
end
plot(x,y,'r')
Hey, thanks a lot for the quick response and the better code! So the key is using the count method. May I ask why the use of empty brackets before the loop? Thanks
Actually it is not needed...For the present code. And thanks is accepting the answer.

Sign in to comment.

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Asked:

on 5 Apr 2017

Commented:

on 6 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!