MathGroup Archive 2005

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

Search the Archive

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


Someonekicked ha scritto:
> 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;
> }
> 
> 

this function in Mathematica would be:

xxx[s_Integer, y_Integer]:=Module[{Q},
    Q = s*y;
    Q
]


more generally:

type_t function( some_input )
{
   int local_var_1;
   double local_var_2;

   local_var_1=somefunction(some_input);
   local_var_2=somefunction(some_input);
   ...
   ...

   return(local_var_2);
}

wolud be:

function[someinput_]:=Module[{local1,local2),
   local1=somefunction[someInput];
   local2=somefunction[someInput];
   ...
   ...

   local2
}

bye


  • Prev by Date: Re: Combinatorica functions doc
  • Next by Date: Re: New to Mathematica- How to write functions????????
  • Previous by thread: Re: New to Mathematica- How to write functions????????
  • Next by thread: Re: Re: New to Mathematica- How to write functions????????