Re: NDSolve with arrays
- To: mathgroup at smc.vnet.net
- Subject: [mg89262] Re: NDSolve with arrays
- From: dh <dh at metrohm.ch>
- Date: Mon, 2 Jun 2008 04:30:56 -0400 (EDT)
- References: <g1m8ev$ia$1@smc.vnet.net> <g1tjkt$ki8$1@smc.vnet.net>
Hi Svend, define the derivatives by: deriv[j_Integer,x_?NumericQ,funvals_]:=funvals[[ If[IntegerPart[Sqrt[j^2+x^2]]>n,n,IntegerPart[Sqrt[j^2+x^2]]] ]]; and replace: D[funs[[j]][x],x]==funs[[x0]][x] by: D[funs[[j]][x],x]== deriv[x0,x,Table[(funs[[i]])[x],{i,1,n}]]: the whole code: n=10; funs=Table[Symbol["f"<>ToString[j]],{j,1,n}]; deriv[j_Integer,x_?NumericQ,funvals_]:=funvals[[ If[IntegerPart[Sqrt[j^2+x^2]]>n,n,IntegerPart[Sqrt[j^2+x^2]]] ]]; tes={Table[funs[[j]][1]->j^2,{j,1,n}]}; Do[eq1[j_]:={D[funs[[j]][x],x]== deriv[x0,x,Table[(funs[[i]])[x],{i,1,n}]],funs[[j]][x0]==(funs[[j]][x0]/.tes[[x0]])}; eqs=Flatten[Table[eq1[j],{j,1,n}]]; AppendTo[tes,NDSolve[eqs,funs,{x,x0,x0+1}][[1]]];,{x0,1,10}]; res=Table[Piecewise@Table[{(funs[[i]]/.Transpose[Drop[tes,1]][[i,j]])[x],x<j+1},{j,1,n-1}],{i,1,10}]; Plot[res,{x,1,4}] hope this helps, Daniel Svend.Domdey at googlemail.com wrote: > to be more precise, > play[x_, j_] :=If[ IntegerPart[x^2+j^2]>n, n, IntegerPart[x^2+j^2]>n], > i.e. the index on the rhs of my equation depends both on j and x. > any suggestions? > thanks > svend > > > On May 29, 2:44 pm, svend <dom... at tphys.uni-heidelberg.de> wrote: >> hi all, >> i want to solve a PDE by discretizing in one variable in an array and solv= > e. the equations are of the following type: >> n = 10; >> x0 = 1; >> x1 = 10; >> >> play[x_] := IntegerPart[x] >> >> eq1 := {D[f[j][x], x] == f[play[x]][x], f[j][x0] == j^2} >> >> eqs = Flatten[Table[eq1, {j, 1, n}]] >> fun = Flatten[Table[f[j], {j, 1, n}]]; >> tes = NDSolve[eqs, fun, {x, x0, x1}][[1]]; >> >> my problem is that the variable x, in which the equation is differential, = > also appears on the rhs in the "index" of my array. mathematica does not eva= > luate "play[x]" during NDSolve and just tells me that the rhs is not numeric= > al. I tried "_NumericQ" and similar things but nothing seems. I would be ver= > y happy if someone could tell me how to resolve this. >> thanks >> svend > > -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh at metrohm.com> Internet:<http://www.metrohm.com>