Re: odd behaviour of `if`
- From: "G. A. Edgar" <edgar@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Apr 2007 08:15:06 -0400
In article <f0m82h$qcl$02$1@xxxxxxxxxxxxxxxxx>, kilian heckrodt
<kilianheckrodt@xxxxxxxxx> wrote:
Hi !
I'm getting bugged by somewhat odd (and for me unexpected) behaviour of
maple:
subs(i=5,`if`(i mod 5 = 0,1,i)) = 5, but `if`(5 mod 5 = 0,1,5) = 1
and in sum and product statement the `if` behaves like with the
substitution.
What's the reason for this behaviour and is there a workaround?
In other words how can if use the `if` in formulas/products/sums ?
You want to evaluate `if`(i mod 5 = 0,1,i) before or after you
substitute i=5? It makes a difference. Use quotes ' ' to
delay evaluation. You can use "eval" instead of "subs" . I
prefer to use "piecewise" instead of "`if`" , but here
I guess it doesn't matter.
eval('`if`(i mod 5 = 0,1,i)',i=5);
1
eval(`if`(i mod 5 = 0,1,i),i=5);
5
eval(piecewise(i mod 5 = 0,1,i),i=5);
5
eval('piecewise(i mod 5 = 0,1,i)',i=5);
1
--
G. A. Edgar http://www.math.ohio-state.edu/~edgar/
.
- References:
- odd behaviour of `if`
- From: kilian heckrodt
- odd behaviour of `if`
- Prev by Date: odd behaviour of `if`
- Next by Date: Re: Selling Matlab and Mathematica addons
- Previous by thread: odd behaviour of `if`
- Next by thread: How compute a big determinant?
- Index(es):
Relevant Pages
|