Prev: How export/recompile expressions and calculation code to run
Next: Combinatorica, TransitiveClosure
From: EF on 31 Jul 2010 02:43 Moin, for the following sample ODE with the variables a[t] and b[t] deqns={a'[t]== -k*a[t], a[0]==2, b'[t]== k*a[t], b[0]==0}; k=0.08; start=0;end=10; the lists vars = {a[t],b[t]} and fvars = {a[t_],b[t_]} are declared. Doing: {a[t_],b[t_]}=vars/.NDSolve[deqns,vars,{t,start,end}][[1]] gives the function values for a[t] and b[t], e.g. a[5] = 1.3406 Using: fvars=vars/.NDSolve[deqns,vars,{t,start,end}][[1]] gives no function values for a[t] and b[t], entering a[5] returns no numeric value. fvars can be plotted however. The Full Forms of the corresponding expressions show no differences. I tried Thread, Map, Apply, Set @@@ etc without result. For ODEs with more than 100 variables, a form like fvars generated from vars would be useful. Please suggest a fix, Thanks E.F.
From: Themis Matsoukas on 1 Aug 2010 04:58 When you executed fvars=vars/.NDSolve[deqns,vars,{t,start,end}][[1]] {InterpolatingFunction[{{0.,10.}},<>][t],InterpolatingFunction[{{0.,10.}},<>][t]} you replaced the previous definition of favrs (which was fvars = {a[t_],b[t_]}) with the result of NDSolve. Your solutions now are in fvars[[1]] and fvars[[2] I am not sure what you are trying to accomplish by setting fvars = {a[t_],b[t_]}. This involves as much typing as fvars=vars/.NDSolve[deqns,vars,{t,start,end}][[1]] {SolvedA[t_],SolvedB[t_]}=fvars By the way, I would recommend that you use a different variable for the solved form of a[t and b[t]. Otherwise, if you execute the notebook a second time, the solved values of a,b, will be used inside NDSolve and you will get unexpected results. Themis
From: EF on 3 Aug 2010 06:42 On 01.08.2010 10:58, Themis Matsoukas wrote: > When you executed > > fvars=vars/.NDSolve[deqns,vars,{t,start,end}][[1]] > {InterpolatingFunction[{{0.,10.}},<>][t],InterpolatingFunction[{{0.,10.}},<>][t]} > > you replaced the previous definition of favrs (which was fvars = {a[t_],b[t_]}) with the result of NDSolve. Your solutions now are in fvars[[1]] and fvars[[2] > > I am not sure what you are trying to accomplish by setting fvars = {a[t_],b[t_]}. This involves as much typing as > > fvars=vars/.NDSolve[deqns,vars,{t,start,end}][[1]] > {SolvedA[t_],SolvedB[t_]}=fvars > > By the way, I would recommend that you use a different variable for the solved form of a[t and b[t]. Otherwise, if you execute the notebook a second time, the solved values of a,b, will be used inside NDSolve and you will get unexpected results. > > Themis > Thanks for your answer, my problem is a bit more complicated. Handling about 1000 variables and the corresponding differential equations in an Simplex loop requires that the program in each cycle handles the variables the Replacements etc. In the meantime I found a solution myself. Declaring var as a list of {a,b} and not {a[t],b[t]} does the trick: Clear[a, b, sol, dgln] var = {a, b}; start = 0; end = 10; k = .08; dgln = {a'[t] == -k*a[t], a[0] == 2, b'[t] == k*a[t], b[0] == 0}; sol = NDSolve[dgln, var, {t, start, end}][[1]]; Set @@@ sol a[5] b[5] E.F.
|
Pages: 1 Prev: How export/recompile expressions and calculation code to run Next: Combinatorica, TransitiveClosure |