Question: I am trying to write a MATLAB code that will apply an expansion factor ( R ) to the nodes in the given parameters. Right

I am trying to write a MATLAB code that will apply an expansion factor (R) to the nodes in the given parameters. Right now, I have the code in terms of a constant expansion (dx). I would like each iteration to be expanding by a Ratio R.
Current code:
clear all; close all; clc;
p=mfilename;
%1D steady state convection diffusion hybrid method
% finite volume
% uniform mesh
%|Pe|=2 central difference
%|Pe|>2 upwind
L=1;
N=20;
dx=L/N;
gamma=0.1;
rho=1;
u=2.0;
Pe=rho*u*L/gamma;
phi_0=0;
phi_L=1;
F=rho*u;
D=gamma/dx;
Pe_x=F/D;
%% Graduates
%coefficients
if Pe_x>2
sprintf('Pe_x =%g,%s', Pe_x, 'upwind')
A_w = ones(N,1)*F;
A_e = zeros(N,1);
elseif Pe_x-2
sprintf('Pe_x =%g,%s', Pe_x, 'upwind')
A_w = zeros(N,1);
A_e = ones(N,1)*(-F);
else
sprintf('Pe_x =%g,%s', Pe_x, 'central')
A_w = ones(N,1)*(D+F/2);
A_e = ones(N,1)*(D-F/2);
end
q_p = zeros(N,1);
q_u = zeros(N,1);
%% Undergrad
% west
if Pe_x>2
A_e(1)=0;
A_w(1)=0;
q_p(1)=-(2*D+F);
q_u(1)=(2*D+F)*phi_0;
elseif Pe_x-2
A_e(1)=-F;
A_w(1)=0;
q_p(1)=-(2*D);
q_u(1)=(2*D)*phi_0;
else
A_e(1)=(D-F/2);
A_w(1)=0;
q_p(1)=-(2*D+F);
q_u(1)=(2*D+F)*phi_0;
end
%east
if Pe_x>2
A_e(N)=0;
A_w(N)=F;
q_p(N)=-(2*D);
q_u(N)=(2*D)*phi_L;
elseif Pe_x-2
A_e(N)=0;
A_w(N)=0;
q_p(N)=F-(2*D);
q_u(N)=-(F-2*D)*phi_L;
else
A_e(N)=0;
A_w(N)=D + F/2;
q_p(N)=-2*D +F;
q_u(N)=(2*D- F)*phi_L;
end
% assembly
A_p = A_w + A_e - q_p;
% TDMA
phi=tdma(-A_w,A_p,-A_e,q_u);
% COORDINATES OF CELL CENTERS
x=linspace(0,L,N+1);
for i=1:N
xc(i)=0.5*(x(i+1)+x(i));
end
% CALCULATE EXACT SOLUTION AND ERROR NORM
ERROR=0;
for i=1:N
phi_ex(i)=phi_0+(exp(xc(i)*Pe/L)-1)/(exp(Pe)-1)*(phi_L-phi_0);
ERROR=ERROR+abs(phi_ex(i)-phi(i));
end
ERROR=ERROR/N
X=[x(1),xc,x(end)];
PHI=[phi_0,phi',phi_L];
PHI_EX=[phi_0,phi_ex,phi_L];
plot(X,PHI,'bs-',X,PHI_EX,'r*-','linewidth',1)
legend('FV','exact')
TDMA Code:
function X = tdma(A,B,C,D)
Cp = C;
Dp = D;
n = length(A);
X = zeros(n,1);
Cp(1)= C(1)/B(1);
Dp(1)= D(1)/B(1);
for i =2:n
Cp(i)= C(i)/(B(i)-Cp(i-1)*A(i));
Dp(i)=(D(i)-Dp(i-1)*A(i))/(B(i)-Cp(i-1)*A(i));
end
X(n)= Dp(n);
for i = n-1:-1:1
X(i)= Dp(i)-Cp(i)*X(i+1);
end:
Graph: (See attached image)
The graph shows evenly distributed iterations along X-axis. I need one that expands by a factor of some ratio R.
I am trying to write a MATLAB code that will

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!