[Date Index]
[Thread Index]
[Author Index]
Re: Re: New to Mathematica- How to write functions????????
*To*: mathgroup at smc.vnet.net
*Subject*: [mg58902] Re: [mg58880] Re: New to Mathematica- How to write functions????????
*From*: Murray Eisenberg <murray at math.umass.edu>
*Date*: Sat, 23 Jul 2005 05:32:09 -0400 (EDT)
*Organization*: Mathematics & Statistics, Univ. of Mass./Amherst
*References*: <dboufp$sse$1@smc.vnet.net> <200507220558.BAA06889@smc.vnet.net>
*Reply-to*: murray at math.umass.edu
*Sender*: owner-wri-mathgroup at wolfram.com
Actually, a more direct Mathematica version would be:
xxx[s_Integer, y_Integer] := s*y
No need for Module (unless you want to do several things); certainly no
need to introduce the superfluous variable Q and to assign the product
x*y to Q!
OT wrote:
> 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
>
>
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
Prev by Date:
**Re: New to Mathematica- How to write functions????????**
Next by Date:
**Empirical CDF**
Previous by thread:
**Re: New to Mathematica- How to write functions????????**
Next by thread:
**Re: New to Mathematica- How to write functions????????**
| |