# Scaling parameters in central difference solution

robby991
Hi, I developed Matlab code to solve the diffusion equation using the central difference equation, with an added term at the end. The equation is the following:

Code:
 dS/dt=Ds*d^2S/dx^2-(Vmax*S/Km+S)

In my code, the length of the space domain is very small, 1E-6. I would like to scale my code to run in the space domain between x = 0 and 1, rather than x = 0 to 1E-6. I propose to introduce a new variable, x2 = x/L. My question is what parameters/variables in my code need to be scaled also. My code is:

Code:
clear all;

numx = 10;                      %number of grid points in space
numt = 1000;                    %number of time steps to be iterated over
tmax = .0045;
Length = 1E-6;                  %length of grid
Ds = .019E-9;                   %requirement Ds(dt)/dx^2 < .5, cm^2/sec
Vmax = 275E-6;                  %mol/cm^2sec
Km = 3E-3;                      %mol/cm^3

x = linspace(0,Length,numx);    %vector of x values, to be used for plotting
t = linspace(0,tmax,numt)';     %vector of t values, to be used for plotting
S = zeros(numt,numx);           %initialize everything to zero

dx = x(2)-x(1);                 %Define grid spacing in time
dt = t(2)-t(1);                 %Define grid spacing in time

%specify initial conditions%

t(1) = 0;      %1st t position = 0

S(1,:) = cos(x*pi/(2*Length));
S(:,numx) = 0;

S_exact = cos(x*pi/(2*Length))*exp(-(pi*sqrt(Ds)/(2*Length))^2*tmax);

%iterate central difference equation%

for j=1:numt-1

%2nd Derivative Central Difference Iteration%

for i=2:numx-1
S(j+1,i) = S(j,i) + (dt/dx^2)*Ds*(S(j,i+1) - 2*S(j,i) + S(j,i-1))-((Vmax*dt*S(j,i))/(Km+S(j,i)));
end

S(j+1,1)=S(j,1)+dt*Ds*2*(S(j,2)-S(j,1))./dx.^2-((Vmax*dt*S(j,i))/(Km+S(j,i)));      %Neumann Boundary Condition

end

plot(x,S(numt,:));
hold on
plot(x,S_exact,'r*')

error = max(S(numt,:)-S_exact)

To scale, the domain would now be:

Code:
x2=x/Length;

and now, dx = x2(2)-x2(1);

How do I change me code to accomodate this? How do my other variables change/scale? i.e. Km, Ds, Vmax etc. Thank you.

Homework Helper
This is exactly the same as working in different units, for example changing your lengths from km to mm (as an example of units which happen to be a factor of 10^6 different)

If you change the values of ALL the constants in your code which have physical dimensions, you don't need to change anything else.

robby991
I have one last question regarding this. Do I have to scale the matrix vectors in the time domain also? I scaled all the parameters related to the space domain (x), but I also have the time vectors (y). If so, do I divide by the same constant I used to scale the space domain?

robby991
I ran into a little difficulty and was wondering if my scaling of parameters was correct in my code. Say I have a grid of length "Length", and instead of going from 0 to Length I want to scale from 0 to 1. In addition I have the following constants in my calculations:

Code:
Length = 1E-4;                  %cm
Ds = .019E-9;                   % cm^2/sec
Vmax = 275E-6;                  %mol/cm^2sec
Km = 3E-3;                      %mol/cm^3

To scale from 0 to 1, I would simply make a new variable L where:
Code:
L = Length/Length.

Next, to scale the other variables I will do the following:

Code:
D = Ds/Length^2
V = Vmax*Length^2
K = Km*Length^3

Is this correct? I would appreciate any input on the matter. Thank you.