haitrungdo82 said:
Δt := 1 min
Δx := 5 m
v := 16.09 km/h
D := 0.17*10^-4 m^2/min
t := 0 ... 1999
x := 1 ... 3999
f_t,x := 1
f_t+1,x := f_t,x - (v*Δt/2)*(f_t,x+1 - f_t,x-1) + [D*Δt/(Δx)^2]*(f_t,x-1 - 2*f_t,x
+ f_t,x+1)
First, your term (v*Δt/2) is going to have units of meters, while the rest of the terms would appear to be unit-less. This is going to result in a units mismatch error. Perhaps this rendering of the program is not correct?
You are also pre-filling the entire f array with 1's, then you proceed to overwrite them all but the first one, f_0,1. Any particular reason for performing all the extra work?
You are using an index of x-1. Since x is defined to go from 1..3999, it will reference f_0.0 which does not exist. You will have to set a starting value there.
When you say that MathCAD crashed, do you mean it locked up (became unresponsive or disappeared altogether), or you you mean that one or more expressions are reporting errors?
Hi qneill,
You made really good comments!
This programming is part of a bigger question. The question wants me to simulate the dipersion of airborne pollutants. More specifically, I have to model numerically the time dependent spatial dispersion of the one-dimensional probability density f(t,x). v is the velocity in x direction of the wind that carries the polluting gas, D is the difussion coefficient. The program requires that, for any given time t, f_x is calculated for all distances x. Then t is increased by D_t, and again f_x is calculated for all distances x, and so on.
f(t=0,x=x_0) = 1 is the initial condition. You're right! I'm also very confused about this initial condition. I think it should be f_t,x-1 = 1, right? But if you look at the attachment, which was copied directly from my Professors's solution which he gave me as a hint, he put f_t,x. May be I misunderstood or misidentified the initial point. That's why I'm very confused!
I noticed the unit inconsistence. But first, I want to follow my Professor's hint (the attachment), then I will go back and take care of the units later. The attached equation is the numerical version of the diffusion equation ( or Fokker-Planck equation).
I think we arrive at the same point of confusion now! Yes, I was also wondering how to define the end points. I think in order to limit the array, all the end points must be defined. Neither the question nor my Professor's hint mentioned about the conditions of the end points, except the initial condition f(t=0,x=x_0) = 1. I think they are implied in the question, but I just can not get it! If I can successfully define the end points, I think I can solve the rest of the question.
When I said "crash", I meant the expression was highlighted in red, i.e. the x+1 or the t+1 indices was highlighted in red. I'm so confused that I don't know which ones I miss and which ones are incorrect.
If you would like more information, I would be happy to give you more. I was just afraid that my post will be deleted if I post the whole question.