Re: Diffusion Model using NDSolve - Advice needed

*To*: mathgroup at smc.vnet.net*Subject*: [mg99437] Re: Diffusion Model using NDSolve - Advice needed*From*: dh <dh at metrohm.com>*Date*: Tue, 5 May 2009 06:03:30 -0400 (EDT)*References*: <gtnk8c$3pa$1@smc.vnet.net>

Hi, it is always better to give an example. E.g. you did not mention if your diffusion problem is tome dependent or stationary. In the following I assume that we have a time independent problem. I further assume that your "slabs" differ in their diffusion constant. DSolve and NDSolve will only yield continuous functions. Consider the diffusion equation (d=diffusion "constant", T=Temp.): d' T' + d T'' ==0 If d is not continuous we will have a problem with d'. Therefore, it is better to introduce a narrow zone where d changes continuously. Here is an example with 2 "slabs" with different diffusion constants =============================================== x1 = 0; x2 = 1; x3 = 1.01; x4 = 2; d[x_] = Piecewise[ {{0.1, x < x2}, {0.1 + 0.9 (x - x2)/(x3 - x2), x < x3}}, 1]; eq = {d[x] T''[x] + d'[x] T'[x] == 0, T[0] == 1, T[x4] == 0 }; sol = T /. DSolve[eq, T, x][[1]]; Plot[sol[x], {x, 0, x4}] =============================================== Note that I used DSolve, not NDSolve. It is always better to get an accurate solution if possible. Note what happens if I use NDSolve: =========================================== sol = T /. NDSolve[eq, T, {x, 0, x4}][[1]]; Plot[sol[x], {x, 0, x4}] ============================================ the solution is wrong! The numerical procedure missed the small zone from x2..x3 and set d'==0 everywhere. We may fix this by e.g. using MaxStepSize or playing with Accuracy or making the zone x2..x3 larger. But still, you Solve if possible. Daniel gwhollywood wrote: > Hey all!! I will try and be really brief. If you think you may know how to help, but don't understand what I'm saying, please ask! I'm desperate for advice. > > I want to use NDSolve to solve the 1-D Diffusion Equation for a "composite slab" with THREE LAYERS, each having an arbitrary thickness and diffusivity. > > I can solve the problem easily using NDSolve for the case of a single layer. > > However I am having a lot of trouble figuring out how to specify the problem for three layers. There should be a separate solution for each layer on its respective part of the domain (the total thickness). > > There are six total boundary conditions. The most important are the four that appear "within" the slab at the two interfaces. They require matching of the flux (which is proportional to the gradient), and proportionality of the concentrations (therefore the solution is not necessarily continuous at the interfaces). > > So it kinda ends up being a piecewise solution - one part valid for a certain section of the composite slab - know what I mean??? > > I have tried entering all the equations (3 second order pde's, three initial conditions, six boundary conditions) in NDSolve but I immediately get the error that some of the boundary conditions specified are NOT at the edge of domain (which is obviously true since they are specified within the layer). Hence one of the three solutions is only valid within its own section of the slab. > > I am having an awful time trying to figure out how to pose this problem within Mathematica. I am fairly proficient with the program in general. > > Any thoughts?? >

**Re: Diffusion Model using NDSolve - Advice needed**

**Re: using FileNames[] on large, deep directories**

**Re: Diffusion Model using NDSolve - Advice needed**

**Re: Diffusion Model using NDSolve - Advice needed**