So it appears that using subscripts in Maple is not a good idea. I ran into this problem for the first time yesterday, and is documented here: http://www.mapleprimes.com/forum/drivenharmonicoscillatoramplitudephaseangle#comment-32780 And now it seems I've run into it again. Or possibly I have made a mistake ;) This is part of an implementation of Newton-Cotes method of numerical integration: restart: NCcoef := proc(N::integer) # procedure returns the Newton-Cotes coefficients for an # appoximation with N+1 points local a,c,p,h,B,LH,RH,eq,seqeq,seqco: h := B/N: p := x->add(a[j]*x^j,j=0..N): LH := int(p(x),x=0..B): RH := h*add(c[k]*p(k*h),k=0..N): eq:=RH-LH: seqeq := seq(coeff(eq,a[k])=0,k=0..N): seqco := seq(c[k],k=0..N): return solve({seqeq},{seqco}); end proc: f:=x->exp(-x^2)/(x+1): a:=1:b:=2:N:=3:h:=(b-a)/N: NCC:=NCcoef(N); # compute the Newton-Cotes formula A:=h*add(c[j]*f(a+j*h),j=0..N); # now evaluate A using the values for c[0], c[1], ..c[N] in NCC eval(A,eval(NCC)); # It fails ! Hmm, so what happens if we do this: NCC_1:= {c[0] = 3/8, c[1] = 9/8, c[2] = 9/8, c[3] = 3/8}; # note NCC_1 *appears* to be the same as NCC above eval(A,NCC_1); # Success. But why doesn't the first eval work ? # This time use underscore instead of subscripts ie, c_||i instead of c[i] restart: NCcoef := proc(N::integer) local a,c,p,h,B,LH,RH,eq,seqeq,seqco: h := B/N: p := x->add(a[j]*x^j,j=0..N): LH := int(p(x),x=0..B): RH := h*add(c_||k*p(k*h),k=0..N): eq:=RH-LH: seqeq := seq(coeff(eq,a[k])=0,k=0..N): seqco := seq(c_||k,k=0..N): return solve({seqeq},{seqco}); end proc: f:=x->exp(-x^2)/(x+1): a:=1:b:=2:N:=3:h:=(b-a)/N: NCC:=NCcoef(N); A:=h*add(c_||j*f(a+j*h),j=0..N); eval(A,eval(NCC)); # It works ! ! ! So, is this another case of the problem with subscripts ?

Please Wait...