MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

Question about parallel operations on lists

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Question about parallel operations on lists
  • From: buchanan at guest2.math.ncsu.edu (Bob Buchanan)
  • Date: Tue, 19 Jan 93 10:27:03 EST

Calling all Mma gurus,

	I'm coding some simple numerical methods for PDE conservation
laws in one of my classes.  Does anyone know a way to clean up the
code of GodunovFlux[] (shown below) so that it doesn't require the
Do[] loops?

Flux[x_] := x	(* simple flux function *)

GodunovFlux[u_List,v_List] :=
	Module[{diff,s,y,fluxu,fluxv},
		diff = Abs[u-v] /. x_ :> 0 /; x < 1/1000;
(* zero out any differences in u-v which are < 0.001 *)
		s = Table[0, {Length[u]}];
		fluxu = Flux[u]; fluxv = Flux[v];
		y = fluxv;
(* if u-v != 0 then compute approximation to derivative *)
		Do[s[[i]] = If[diff[[i]] > 0, 
				(fluxu[[i]] - fluxv[[i]])/(u[[i]] - v[[i]]),
				s[[i]]],
			{i,Length[u]}];
(* if previous result > 0 then y <- fluxu *)
		Do[y[[i]] = If[s[[i]] > 0,fluxu[[i]],y[[i]]],
			{i,Length[u]}];
		y]

Basically, I'm looking for an elegant (or arcane) way to avoid doing so
much of this calculation element-wise.

Thanks,
Bob Buchanan	(Bob_Buchanan at ncsu.edu)





  • Prev by Date: Constructing distributions from data
  • Next by Date: contour graphics
  • Previous by thread: Constructing distributions from data
  • Next by thread: contour graphics