I am having problem with if and assume statements. Some times they work and other times I get error. Problem is the if block in pgm12 where I print out the index based upon if condition.
First call to the code (res2) works but fails in the 2nd case. Using the facts I can see that I should get an integer number from the if block but I do not. Thanks
Ram
Maxima version: 5.15.0Maxima build date: 17:36 4/20/2008host type: i686-pc-mingw32lisp-implementation-type: GNU Common Lisp (GCL)lisp-implementation-version: GCL 2.6.8
Error:.
------------------------------------------------------------------------------------
(%o14) [1,1,1,1,1]
The context _cntx3_ doesn't exist.
1 3 [x>=1,3>x]
_cntx3_()
true [x>=1,3>x]
4
unknown [x>=1,3>x]
false [x>=1,3>x]
false [x>=1,3>x]
3 4 [x>=3,4>x]
_cntx3_()
false [x>=3,4>x]
true [x>=3,4>x]
5
false [x>=3,4>x]
false [x>=3,4>x]
4 6 [x>=4,6>x]
_cntx3_()
false [x>=4,6>x]
false [x>=4,6>x]
unknown [x>=4,6>x]
false [x>=4,6>x]
Subscript must be an integer:ith#0:
pgm12(n=6,k=4,x=x,tlis=[1,1,1,1,3,4,6,6,6,6])#1: comp12(n=6,k=4,t=[1,1,1,1,3,4,6,6,6,6]) -- an error. To debug this try debugmode(true);
(%i16) facts();
(%o16) [x>=4,6>x]
I have extracted the portion of the code where error occurs. Thanks for help
-------------------------------Code---------------------------
comp12:lambda([n,k,t],
block([a, b, ii, len, res, s, ss],
ii:0,
ss:setify(t),
a:first(ss),
s:rest(ss,1),
len:length(ss)-1,
res:make_array(any,len),
killcontext(_cntx3_),
newcontext(_cntx3_),
for si in s do
(
b:si,
assume(x >= a and x<b),
print(a,b,facts(x)),
res[ii]:pgm12(n,k,x,t),
forget(x >= a and x<b),
a:si,
ii:ii+1
),
killcontext(_cntx3_),
res
))$
/** error in ith variable assignment **/
pgm12(n,k,x,tLis):=block([j,ith, r,btmp,res,t:float(tLis),dl,dr,bp],
print(context()),
for j:k thru n+1 do
( print(is(t[j] <= x and t[j+1] > x),facts()),
if (t[j] <= x and t[j+1] > x) then
(ith:j,print(ith))),
res:make_array(any,k),
r1:if (x>=t[ith] and x<t[ith+1]) then 1 else 0
)$
---------------------------------Input--------------------------------------------------
f:lambda([x,y],max(x-3.5,0.)^2 + max(y-3.,0.)^3);
k1:3;
n1:7;
k2:4;
n2:6;
t1:[1,1,1,5/2,7/2,9/2,11/2,7,7,7];
t2:[1,1,1,1,3,4,6,6,6,6];
x1:[1,2,3,4,5,6,7];
x2:[1,2,3,4,5,6];
ratprint:false;
res2:comp12(n1,k1,t1)$
res2:factor(listarray(res2));
comp12(n2,k2,t2); /** ith variable is not defined even though x>= 4 and x<6 **/
---------------------------------------------------------------------------------------------------------------