MathGroup Archive 2005

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

Search the Archive

Re: New to Mathematica- How to write functions????????


On Jul 21, 2005, at 3:46 PM, Someonekicked wrote:

> new to mathematica, looked at the help, but did not get the help i  
> needed..
>
> I want to write a function that does multiple calculations in its  
> body, then
> it returns a value.
> I am talking about functions similar to functions that you can  
> declare in
> C++.
> can anyone give me an example?
>
>
> in C++, a function would be like, (note int means integer)
>
> int zzz(int s, int y)
> {
>    int  Q;
>    Q = s*y;
>    return Q;
> }
>
>
> well thats just a simple example, the body of my function is going  
> to be
> complicated...
> I know in mathematica, I can solve the same zzz by
> zzz[s_,y_] := s*y;
>
> However, what if i want the body more complicated and do more than one
> thing??

Look into Block, Module, and With.

Also compound expressions in Mathematica are separated with ;, for  
example

zzz[s_,y_]:=Block[{t},t=s y;2 t]

returns the value of the last expression (2 t) in the compound  
expression t=s y;2 t.

Regards,

Ssezi


  • Prev by Date: Re: New to Mathematica- How to write functions????????
  • Next by Date: Re: a bad demonstration of Mathematica's MathML capabilities
  • Previous by thread: New to Mathematica- How to write functions????????
  • Next by thread: Re: New to Mathematica- How to write functions????????