From: Clint Zeringue on 19 Feb 2010 03:32 Hello, I have a quick question regarding the use of a pseudo-random scource inside NDsolve. Suppose you have the following: scource[z_,]:= RandomReal[{-5,5}] Then in NDsolve we have NDsolve[f'[z] + f[z] == scource[z],f,{z,0.5}] My question is as the integrator works to solve this system within NDsolve is it really putting in a random number at each z-step? or is it just evaluated scource[z] once and returning a number, and then going into the integrator?' Nevertheless, How can I keep the algorithm that is actually solving this system to pull random numbers at each z step? Thanks, -Clint
From: Albert Retey on 19 Feb 2010 07:35 Hi, > I have a quick question regarding the use of a pseudo-random scource > inside NDsolve. > > Suppose you have the following: > > scource[z_,]:= RandomReal[{-5,5}] > > Then in NDsolve we have > > NDsolve[f'[z] + f[z] == scource[z],f,{z,0.5}] > > My question is as the integrator works to solve this system within > NDsolve is it really putting in a random number at each z-step? or is > it just evaluated scource[z] once and returning a number, and then > going into the integrator?' It is pulling a random number at each time step. The problem is that by default NDSolve uses a variable time step solver and for a random right hand side it will choose the steps size to be so small that you will either not see the desired effect or it will stop with error messages because the step size will "effectively be zero" (you might probably see different messages). I think that strictly speaking the equation as you have written down does not even make much sense when interpreted in a "continous" way. In a differential equation there is nothing like a time step, time steps iare just artifacts of the numerical algorithms to solve differential equations. > Nevertheless, How can I keep the algorithm that is actually solving > this system to pull random numbers at each z step? The question has come up more than once and you should find various ways to get a result that reflects what you need in the archives, see e.g. this thread: <http://groups.google.at/group/comp.soft-sys.math.mathematica/browse_thread/thread/c5be1fabf6496c3b/4296c62cc35373d0?hl=de&lnk=gst&q=NDSolve+Random#4296c62cc35373d0> or just search for NDSolve and Random in e.g. google groups. hth, albert
From: David Bailey on 20 Feb 2010 06:38 Clint Zeringue wrote: > Hello, > > I have a quick question regarding the use of a pseudo-random scource inside NDsolve. > > Suppose you have the following: > > scource[z_,]:= RandomReal[{-5,5}] > > Then in NDsolve we have > > NDsolve[f'[z] + f[z] == scource[z],f,{z,0.5}] > > My question is as the integrator works to solve this system within NDsolve is it really putting in a random number at each z-step? or is it just evaluated scource[z] once and returning a number, and then going into the integrator?' > > Nevertheless, How can I keep the algorithm that is actually solving this system to pull random numbers at each z step? > > Thanks, > > -Clint > You really don't want to think about z-steps when you use NDSolve, because NDSolve will use whatever size steps it wants, and it really requires that your function be consistent and preferably continuous :) This problem crops up in simpler contexts than NDSolve, for example, it makes no sense to plot a function such as: Plot[Sin[z]+Random[],{z,0,10}] because the 'frequency' of the random fuzz introduced will depend on the step size that Plot uses. You really need to think a bit more about what your function really is - perhaps you should create a list of equally spaced random points, and generate an interpolation between them to create your random source in a step-independent way. David Bailey http://www.dbaileyconsultancy.co.uk
|
Pages: 1 Prev: Convexity and graphical display of feasible set Next: Poisson-Boltzmann equation |