MathGroup Archive 2006

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

Search the Archive

RE: problem with modules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72247] RE: [mg72228] problem with modules
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Sat, 16 Dec 2006 05:18:01 -0500 (EST)

Hi Jamie,

> I do not understand how to return a result from a module so 
> that I can use the result globally. I am trying to generate 2 
> matrices from the module.
> For example,
> ludecomp[n_,A_]:=Module[{...},
> ...;
> Return[U//MatrixForm]
> Return[L//MatrixForm]]
> When I type ludecomp[n,A], it returns a result, however, when 
> I try to input just the variable U, it doesn't return a 
> value. I'd greatly appreciate any help that you can offer!

That is because your module is defined for two arguments only.  By the way,
if n_ is the matrix size, then you don't need this as an argument since you
can ask the matrix for this internally (dims = Dimensions[A]).  This makes
translating Fortran a bit clearer.

As to returning different arguments, the easiest way is to set up options.

	Options[ludecomp] = {DefaultOutput -> "Both"};
	ludecomp[oneArg_, opts___] := Module[...];

Somewhere in your module, you'll need to do something like

	mOutput = DefaultOutput /. {opts} /. Options[ludecomp];

To see what you're going to output and

	actualOutput = Switch[mOutput,
		Both, {L, U},
		Upper, U,
		Lower, L
		];

At the end of your module.  You don't need Return[] (just make the returned
output is the last line in the module) but it does help (IMHO) readability
as you can easily see exactly what is returned.

Regards,

Dave.


  • Prev by Date: Re: Can FindFit handle two dependent variables?
  • Next by Date: Re: Missing <<Miscellaneous`PhysicalConstants` package
  • Previous by thread: RE: problem with modules
  • Next by thread: Missing <<Miscellaneous`PhysicalConstants` package