Message Boards Message Boards

0
|
3485 Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Defining modules and module function

Posted 10 years ago

Define a module and module function, mF, that calculate the maximum of xand y, and then find the maximum of the values (34/9, 674/689).

POSTED BY: sam adams
7 Replies
Posted 10 years ago

mF[x, y] := Module[{x0 = x, y0 = y}, If[x0 > y0, x0, y0]];

ended up doing it like as show above

POSTED BY: sam adams
Posted 10 years ago

Ok cheers it was suggested to me to do that but forget it Thanks

POSTED BY: sam adams
Posted 10 years ago

Am i right in thinking I have to create internal variables and use those instead of comparing x and y directly, if so how?

POSTED BY: sam adams

You do not need to create extra variables. Why copy the input arguments to another variables in order to compare them? Waste of memory and CPU time since they will not be changed. You need to make a copy only if you want to modify the input argument inside the Module.

POSTED BY: Nasser M. Abbasi
Posted 10 years ago

Thanks but i believe i needed to use an IF function which confuses me ???

POSTED BY: sam adams

I updated it to use If

POSTED BY: Nasser M. Abbasi

define the Module

mF[x_, y_] := Module[{}, Max[x, y]];

Use it to find the max

mF[34/9, 674/687]
 (*34/9*)

To use If use this:

mF[x_, y_] := Module[{}, If[x > y, x, y]]
mF[34/9, 674/687]
    (*34/9*)
POSTED BY: Nasser M. Abbasi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract