Sponsored links: Algebra eBooks
 

Related

errcatch-load-subst

load ("lrats");

subst ([a = b, c = d...

lratsubst ([a^2 = b,...

Calculate

errcatch-load-subst

load ("lrats");

subst ([a = b, c = d...

lratsubst ([a^2 = b,...

Calculate

errcatch

Run Example
(%i1)intervals(items):=block([result],  result: if (emptyp(items)) then [] else           if(listp(items)) then          if(emptyp(rest(items))) then [] else          cons(cons(first(items),  [second(items)]),          intervals(rest(items))));
(%o1) intervals(items) := block([result], 
result : if emptyp(items) then [] else (if listp(items)
 then (if emptyp(rest(items)) then [] else cons(cons(first(items), 
[second(items)]), intervals(rest(items))))))
(%i2) intervals(makelist(n, n, 1, 10));
(%o2) [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]
(%i3) intervals(makelist(n, n, 1, 11));
(%o3) [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], 
                                                             [9, 10], [10, 11]]
(%i4) ans:errcatch(find_root(sin(x), x, 2, 3));

find_root: function has same sign at endpoints: f(2.0) = 0.90929742682568, 
                                                      f(3.0) = 0.14112000805987
(%o4)                                 []
(%i5) ans;
(%o5)                                 []
(%i6) seq(start,stop,stepping,[shift]) := block([                                            n, y:[],                                             shift: (if (not(emptyp(shift)))                                                         then float(first(shift))                                                            else (0.0))                                            ],            (n:floor((float(stop-start)/float(stepping)))),            (if (start <
 stop)            then            (y:flatten(append([y],                                         makelist(float(start+shift+(stepping*(i-start))),                                         i, start, n+start))))            else            (y:flatten(append([y],                                         makelist(-(float(stop-shift-(stepping*(i-stop)))),                                         i, -(n+stop), stop)))))            (if (n>
1.0)                then return(y)                else return([])));
(%o6) seq(start, stop, stepping, [shift]) := 
block([n, y : [], shift : if not emptyp(shift) then float(first(shift))
                      float(stop - start)
 else 0.0], n : floor(-------------------), 
                        float(stepping)
if start < stop then y : flatten(append([y], 
makelist(float(start + shift + stepping (i - start)), i, start, n + start)))
 else y : flatten(append([y], makelist(- float(stop - shift
 - stepping (i - stop)), i, - (n + stop), stop)))(if n > 1.0 then return(y)
 else return([])))
(%i7) intervals(seq(0,7,1));
(%o7) [[0.0, 1.0], [1.0, 2.0], [2.0, 3.0], [3.0, 4.0], [4.0, 5.0], [5.0, 6.0], 
                                                                    [6.0, 7.0]]
(%i8) ans:[];
(%o8)                                 []
(%i9) %pi;
(%o9)                                 %pi
(%i10) %pi, numer;
(%o10)                         3.141592653589793
(%i11) 2*3.14159/%pi;
                                    6.28318
(%o11)                              -------
                                      %pi
(%i12) block([ans:[]], errormsg:false, for i in intervals(seq(0, 7, 1)) do ans:(append(ans, errcatch(find_root(sin(x), x, first(i), second(i))))), errormsg:true, return(ans));
(%o12)            [0.0, 3.141592653589793, 6.283185307179586]
(%i13) 
Run Example
seq(start,stop,stepping,[shift]) := block([                                            n, y:[],                                             shift: (if (not(emptyp(shift)))                                                         then float(first(shift))                                                            else (0.0))                                            ],            (n:floor((float(stop-start)/float(stepping)))),            (if (start <
 stop)            then            (y:flatten(append([y],                                         makelist(float(start+shift+(stepping*(i-start))),                                         i, start, n+start))))            else            (y:flatten(append([y],                                         makelist(-(float(stop-shift-(stepping*(i-stop)))),                                         i, -(n+stop), stop)))))            (if (n>
1.0)                then return(y)                else return([])));
(%o1) seq(start, stop, stepping, [shift]) := 
block([n, y : [], shift : if not emptyp(shift) then float(first(shift))
                      float(stop - start)
 else 0.0], n : floor(-------------------), 
                        float(stepping)
if start < stop then y : flatten(append([y], 
makelist(float(start + shift + stepping (i - start)), i, start, n + start)))
 else y : flatten(append([y], makelist(- float(stop - shift
 - stepping (i - stop)), i, - (n + stop), stop)))(if n > 1.0 then return(y)
 else return([])))
(%i2) kill(pairs);
(%o2)                                done
(%i3) pairs(items):=block([result],  result: if (emptyp(items)) then [] else           if(listp(items)) then          if(emptyp(rest(items))) then [last(items)] else          cons(cons(first(items),  [second(items)]),          pairs(rest(rest(items)))));
(%o3) pairs(items) := block([result], result : 
if emptyp(items) then [] else (if listp(items)
 then (if emptyp(rest(items)) then [last(items)]
 else cons(cons(first(items), [second(items)]), pairs(rest(rest(items)))))))
(%i4) pairs(seq(1, 10, 1));
(%o4)    [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [7.0, 8.0], [9.0, 10.0]]
(%i5) test(list):=block([val:''list, result, m, n],m:first(first(val)), n:second(first(val)),find_root(sin(x), x, m, n));
(%o5) test(list) := block([val : list, result, m, n], m : first(first(val)), 
                            n : second(first(val)), find_root(sin(x), x, m, n))
(%i6) test(pairs(seq(0, 10, 1)));
(%o6)                                 0.0
(%i7) a:pairs(seq(0, 10, 1));
(%o7) [[0.0, 1.0], [2.0, 3.0], [4.0, 5.0], [6.0, 7.0], [8.0, 9.0], 10.0]
(%i8) for i in a do print(i);
[0.0, 1.0] 
[2.0, 3.0] 
[4.0, 5.0] 
[6.0, 7.0] 
[8.0, 9.0] 
10.0 
(%o8)                                done
(%i9) test2(list):=block([val:''list, result:[], m, n, l], for i in val do (m:first(i),n:second(i),result:errcatch(find_root(sin(x), x, m, n))));
(%o9) test2(list) := block([val : list, result : [], m, n, l], 
for i in val do (m : first(i), n : second(i), 
result : errcatch(find_root(sin(x), x, m, n))))
(%i10) test2(pairs(seq(0, 9, 1)));

find_root: function has same sign at endpoints: f(2.0) = 0.90929742682568, 
                                                      f(3.0) = 0.14112000805987
find_root: function has same sign at endpoints: f(4.0) = - 0.75680249530793, 
                                                    f(5.0) = - 0.95892427466314
find_root: function has same sign at endpoints: f(8.0) = 0.98935824662338, 
                                                      f(9.0) = 0.41211848524176
(%o10)                               done
(%i11) errcatch(find_root(sin(x), x, 2, 3));

find_root: function has same sign at endpoints: f(2.0) = 0.90929742682568, 
                                                      f(3.0) = 0.14112000805987
(%o11)                                []
(%i12) 
Run Example
pairs(items):=block([result],  result: if (emptyp(items)) then [] else           if(listp(items)) then          if(emptyp(rest(items))) then [last(items)] else          cons(cons(first(items),  [second(items)]),          pairs(rest(rest(items)))));
(%o1) pairs(items) := block([result], result : 
if emptyp(items) then [] else (if listp(items)
 then (if emptyp(rest(items)) then [last(items)]
 else cons(cons(first(items), [second(items)]), pairs(rest(rest(items)))))))
(%i2) pairs(makelist(n, n, 1, 10));
(%o2)              [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
(%i3) pairs(makelist(n, n, 1, 11));
(%o3)            [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], 11]
(%i4) errcatch(find_root(sin(x), x, 2, 3));

find_root: function has same sign at endpoints: f(2.0) = 0.90929742682568, 
                                                      f(3.0) = 0.14112000805987
(%o4)                                 []
(%i5) 
[abs,append,block,emptyp,errcatch,errormsg,find_root,first,flatten,floor,if,listp,makelist,not,numer,rest,second,sin] [append,block,do,emptyp,errcatch,errormsg,false,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,do,emptyp,errcatch,find_root,first,flatten,floor,if,last,listp,makelist,not,rest,second,sin] [append,block,do,emptyp,errcatch,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,errormsg,false,find_root,first,flatten,floor,if,listp,makelist,not,print,rest,second,sin] [append,block,emptyp,errcatch,errormsg,false,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,errormsg,find_root,first,flatten,floor,if,listp,makelist,mod,not,numer,rest,second,sin] [append,block,emptyp,errcatch,errormsg,find_root,first,flatten,floor,if,listp,makelist,not,numer,rest,second,sin] [append,block,emptyp,errcatch,errormsg,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,errormsg,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,find_root,first,flatten,floor,if,last,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,find_root,first,flatten,floor,if,listp,makelist,not,rest,second,sin] [append,block,emptyp,errcatch,find_root,first,flatten,floor,kill,last,listp,makelist,not,rest,second,sin] [block,emptyp,errcatch,find_root,first,if,last,listp,makelist,rest,second,sin]

Related Help

Help for Errcatch