Is there a way to build an if statement with two conditions such as:
if[a>b and a>0,...]. If there is, could you let me know the syntax?
Thanks
nt
g[x_, y_] := If[And[x > y, Mod[x, 2] == 0], 1, 0]
mat = Table[{x, y}, {x, 0, 4}, {y, 0, 4}];
Apply[f, mat, {2}]
{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{1, 1, 0, 0, 0}, {0, 0, 0, 0, 0},
{1, 1, 1, 1, 0}}
% == Apply[g, mat, {2}]
True
Bob Hanlon
---- nt <sagitta...@gmail.com> wrote:
=============
a = 3;
b = 2;
If[a > b && a > 0, Print["correct"], Print["try again"]]
or
a = 3;
b = 2;
If[And[a > b, a > 0], Print["correct"], Print["try again"]]
?If
--Nasser
Hello
I believe this is what you're looking for:
If[ a>b && a>0 , ... ]
or in FullForm:
If[ And[a>b, a>0] , ... ]
Bobby
On Tue, 30 Mar 2010 05:01:24 -0500, nt <sagitta...@gmail.com> wrote:
> Hi all,
>
> Is there a way to build an if statement with two conditions such as:
> if[a>b and a>0,...]. If there is, could you let me know the syntax?
>
> Thanks
> nt
>
>Is there a way to build an if statement with two conditions such as:
>if[a>b and a>0,...]. If there is, could you let me know the syntax?
Either
If[a>b && a>0, ...]
or
If[And[a>b, a>0, ...]
will do what you want
If[ And[ a>b, a>0], ...]
There are a number of ways to write it
If[ (a>b)~And~(a>0), ...],
If[ (a>b) && (a>0), ...]
Most people like the last one.
Daniel
If not, you might begin by using the search field in the Documentation
Center to look up each of:
if
and
Actually, unless you're a complete novice at Mathematica, you'd already
know that the names of built-in objects always begin with an upper-case
letter, so you'd save some time sifting through lists of references by
looking up instead each of:
If
And
On 3/30/2010 6:01 AM, nt wrote:
> Hi all,
>
> Is there a way to build an if statement with two conditions such as:
> if[a>b and a>0,...]. If there is, could you let me know the syntax?
>
> Thanks
> nt
>
--
Murray Eisenberg mur...@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
If[a>b && a>0, ...]
The documentation is your friend and will list all logical operators.