Scaling parameters in central difference solution

Click For Summary

Discussion Overview

The discussion revolves around scaling parameters in a Matlab code designed to solve the diffusion equation using the central difference method. Participants explore how to adjust various parameters when changing the spatial domain from a very small length to a larger scale, as well as considerations for the time domain.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant describes their Matlab code for solving the diffusion equation and seeks advice on how to scale parameters when changing the spatial domain from 1E-6 to a range between 0 and 1.
  • Another participant suggests that scaling parameters with physical dimensions is akin to changing units, indicating that all constants should be adjusted accordingly without changing the code structure.
  • A participant inquires whether time domain vectors also need to be scaled in the same manner as spatial parameters, questioning if the same scaling factor applies.
  • Another participant discusses their approach to scaling parameters when changing the grid length from 0 to Length, proposing specific scaling formulas for various constants, such as dividing Ds by Length squared and multiplying Vmax by Length squared.

Areas of Agreement / Disagreement

There is no clear consensus on the scaling of time domain parameters, as one participant raises a question about whether the same scaling factor applies, indicating uncertainty in that area. The scaling of spatial parameters appears to be more straightforward, but the discussion remains open regarding the specifics of time scaling.

Contextual Notes

Participants express varying levels of confidence in their proposed scaling methods, and there are unresolved questions about the implications of scaling in the time domain. The discussion includes assumptions about the relationships between different parameters that may not be universally accepted.

robby991
Messages
37
Reaction score
1
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 accommodate this? How do my other variables change/scale? i.e. Km, Ds, Vmax etc. Thank you.
 
Physics news on Phys.org
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.
 
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?
 
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.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
9K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 0 ·
Replies
0
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K