- #1

robby991

- 41

- 1

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.