sum() ind subs()

Why does Maple not substitute the value for y[1] in the result?

subs(m=3,y[1]=2,sum(r[i]*y[i],i=1..m));%;<br />

I assume that the values were substituted in sum() but subs() does not execute sum(). Accordingly there is at the timepoint of substitution no y[1] in sum()?

Thanks
Dirk

One way

This is a way that works, though I do not like much:

eval(sum(r[i]*y[i],i=1..m),[m=3,sum=add,y[1]=2]);

Robert Israel's picture

sum and subs

The short answer to "why" is that sum(r[i]*y[i], i=1..m) does not actually contain y[1]. See for yourself:

> sum(r[i]*y[i], i=1..m);

sum(r[i]*y[i], i=1..m)

No y[1] there! One thing you could do is this:

> eval(eval(sum(r[i]*y[i],i=1..m),m=3),y[1]=2);

2*r[1]+r[2]*y[2]+r[3]*y[3]

Note: I use eval rather than subs, to have the result evaluated after substitution.

John Fredsted's picture

Disregard this post

Please, disregard this post. The previous content was misconceived.

Yes, but you have insert

Yes, but you have insert i=1..3 instead of i=1..m in your equation above. In this case you would not need the m=3 in subs().

John Fredsted's picture

Quite correct

You are quite right, which is why I withdraw my post. I apologize.

I did not see your response,

I did not see your response, as I sent my answer. Sorry for that.

John Fredsted's picture

I reckoned that

I reckoned that. I hope that you have received a useful answer from the others, because these postings of mine surely are of no help :-).

It does appear to be the evaluation order.

Here are two ways of trying to do this. The first does not work,
the sum is not evaluated.

subs(y[1]=2,subs(m=3,sum(r[i]*y[i],i=1..m)));

The next works, with a forced evaluation.

subs(y[1]=2,eval(subs(m=3,sum(r[i]*y[i],i=1..m))));

If you look at the help on sum in Maple 11 you will find
the following statement.

"Maple returns the call unevaluated if it cannot find a closed form."

Since you do not have a closed form, Maple does not evaluate the sum
and there is no "y[1]."

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}