I’m building a model for breakthrough/adsorption. I’m not well versed in the mathematica programming and learn best by reverse-engineering an existing code. I learned most of my stuff from this demonstration.
My code has three major parts. Everything uses a position and time dimension [z,t].
An interation loop that makes a table (mytable) where the elements of the table are InterpolatingFunctions calculated and stored during the loop.
The Adsorption isotherm equation. This is set up as a “set delay” function, I think its called. This function q[z_,t_] = K*c[z,t] is called up by part 3.
The NDSolve section. The main function is solving:
NDSolve[
D[c[z,t],t] = mass balance + D[q[z,t],t].
]
I’m attempting to incorporate the interpolation functions, where the table part is chosen based on a function of z. Therefore part 2 becomes
q[z_,t_] = K*c[z,t] * mytable[[ F(z) ]][c[z,t]]
When I run this program I get an error where it says that F(z) is not a integer/part specification. When I added this part to the code, I’d assumed that the value of z would be “brought in” by the delay mechanism in the same way that q is brought into the NDSolve. It seems instead that z is not a number “yet” and causes the error.
So, my question is: Is it possible to do this in the way I have it set up? Perhaps I have a syntax error or something. OR, if it is not possible with this rough lookup table method, how would I be able to incorporate a FindRoot function within NDSolve where the zeroes depend on the value of c[z,t]? ALSO, is there a good demonstration code which has similar functionality?
I can’t provide my code right now, but I may be able to provide a trimmed down and readable version if needed.
Thanks, but that was more for show, not so much as it is in my code. Actually, it is mytable[[ 1 + Round[ (z - zo) / L ] ]] where zo and L are constants. It is simply meant to calculate an index for the “part assignment”. The problem is as the code passes that section of code q[z_,t_] = K*c[z,t] * mytable[[ 1 + Round[ (z - zo) / L ]][c[z,t]] I get an error that the function which uses z is not an integer and can’t be used in the “part assignment”.
Thank you. It doesn’t seem to work as I still get the error as copied below.
Part::pspec: "Part specification 1+Round[1/5\ (55-27\ z)] is neither an integer nor a list of integers. This is the same as before.
The way I changed my code is that I now have,
Do[
mytable[]=stuff; “This builds a table of InterpolatingFunction <> which will later be used based on c[z,t] values”;
]
zpart=Round[ func ]+1; “This produces an index from 1 to whatever as whole numbers”;
q[z_,t_] = ( K*c[z,t] ) * ( mytable[[ zpart ]][c[z,t]] ); “This calculates uptake which is taken as a derivative in the NDSolve section below”;
NDSolve[
D[c[z,t],t] = mass balance + D[q[z,t],t];
]
Thank you for your help
EDIT:
This is strange, the code I have up there is not publishing as I typed it. func [ z ] and zpart [ z ] is turning into func and zpart within the double brackets. I assume mathematica may be doing something similar, but I don’t know what it is doing behind the scenes.
Question for you. Should the zPart be inside the NDSolve section, or outside as it is now?
I think the additional Part::pspec message comes when NDSolve evaluates its first argument, where z is a symbol.
To prevent that, clear any previous definitions of q and define it as q[z_?NumericQ, t_] := …
Hi Greg,
I hope you find the answer to your question. I am on the same path, and I am kind of beginner with Mathematica. If you successfully run your program do you mind guide me on how to get it worked.
Thank you.