MathGroup Archive 1998

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

Search the Archive

Re: Defining a Function??



Corey & Alicia Beaverson wrote:
> 
> Below is a program that I have written, with much help from the critique
> on my last program...thanks everybody!. Anyway, if I define all of the
> varibles as global, the program runs and outputs the results. I want to
> set it up as a function though so I can use it for more than one case.
> I am not sure what I am doing wrong here but for some reason it does
> not seem to run, instead it just gives me the input back.....Thanks in
> advance!!!
> 
> In[29]:=
> 
> OneDPlaneWall[L_,rho_,k_,c_,Tinfo_,TinfL_,ho_,hL_,time_,T_,n_]:=
>  Module[{ alpha, deltax, Bio, BiL, foo, foi,foL, deltat, fo},
>      alpha=k/(rho*c);
>   deltax=L/(n-1);
>   Bio=(ho*deltax)/k;
>   BiL=(hL*deltax)/k;
>   foo=1/(2(1+Bio));
>   foi= 0.5;
>   foL=1/(2(1+BiL));
>   fo=Min[foo,foi,foL];
>   deltat=(fo(deltax)^2)/alpha;
>   T=Table[T, {n}];
>   While[ Min[T]>0,
>     time=time+deltat;
>    T[[1]]=((1-2*fo-2*Bio*fo)T[[1]] +fo*2(T[[2]]+Bio*Tinfo));
>     T[[Range[2,n-1]]]=
>         Table[Int=((1-2*fo)T[[i]]+fo(T[[i-1]]+T[[i+1]])), {i,2,n-1}];
>    T[[n]]=((1-2*fo-2*BiL*fo)T[[n]]+fo*2(T[[n-1]]+BiL*TinfL))];]
>        T
>   time
> 
> Out[30]=
> Table[T,{n}]
> Out[31]=
> time
> In[32]:=
> OneDPlaneWall[0.25,1860,0.72,17,-6,100,60,0,17,11] Out[32]=
> OneDPlaneWall[0.25,1860,0.72,17,-6,100,60,0,17,11]


You have instructed it not to return anything by putting a semicolon on
your last statement in the module construct.  Module returns as a value
whatever the last statement is or the results of the first Return[]
statement it executes.

As good programming practice so that I can quickly see what a function
is supposed to return, I always include a Return statement at the end
of my modules ie:

foo[x_,y_,...]:=
	Module[{a,b,c,d,...},
	expr1;
	expr2;
	...;
	Return[answer]]

The other thing to beware of is that if you leave out even one parameter
from the list or misspell the name of the function (remember,
Mathematica is case sensitive), then Mathematica will just return your
input. -- 
Remove the _nospam_ in the return address to respond.



  • Prev by Date: file size?
  • Next by Date: Re: [Q] how to use simple notation to combine many graphicsMime-Version: 1.0
  • Prev by thread: Defining a Function??
  • Next by thread: Re: Defining a Function??