0

I want the entries of a Maxima list to be rounded in Excel style using Robert Dodier's excel_round.mac (see Maxima: Round like in Excel) on the fly.

I created a list, say the values of exp(0.5*x) over the range from [-2,2].

(%i1)  makelist(exp(0.5*x),x,-2,2)$
       soln: %
(%o1) [0.36788,0.60653,1,1.6487,2.7183]

The problem I'm having is how to get all the list entries into the x of below.

(%i1)  excel_round(x,2)$
       ev(%, x=?)   

As trying the following

(%i2)  map(exel_round(x,2),soln);       
(%o2)  [exel_round(x,2)(0.36788),exel_round(x,2)(0.60653),  
       exel_round(x,2)(1),exel_round(x,2)(1.6487),exel_round(x,2)(2.7183)]

and

(%i12)  makelist(exp(0.5*x),x,-2,2);  
        soln: %$
        excel_round(x,2)$  
        ev(%, x=soln)
(%o12)  [0.36788,0.60653,1,1.6487,2.7183]  
(%o15)  excel_round([0.36788,0.60653,1,1.6487,2.7183],2)

didn't yield the desired results I returned to semi-brute force:

(%i18)  excel_round(x,2)$
            ev(%, x=soln[1]);
        excel_round(x,2)$
            ev(%, x=soln[2]);  
        excel_round(x,2)$  
            ev(%, x=soln[3]);  
        excel_round(x,2)$  
            ev(%, x=soln[4]);  
        excel_round(x,2)$  
            ev(%, x=soln[5])
(%o19) 0.37  
(%o21) 0.61  
(%o23) 1.0  
(%o25) 1.65  
(%o27) 2.72

This is probably better than typing in all the list entries by hand. There surely must be a better and more elegant way.

Any help/suggestions welcome.

  • To map a function of two arguments over a list (with one argument being the same in all cases), construct a lambda expression (unnamed function) and map that over the list. E.g.: `map (lambda ([x], excel_round (x, 2)), %o1);` where `%o1` is the list of numbers. – Robert Dodier Mar 04 '22 at 05:08
  • 1
    It would be interesting if a function of two arguments with one argument specified became a function of one argument which you could then apply. That would make `excel_round(x, 2)(0.123456)` work. Maxima doesn't work that way, but, if I am not mistaken, Haskell does, via an operation called "function currying". – Robert Dodier Mar 04 '22 at 05:10
  • Dear @RobertDodier , thanks for your fast reply. `map (lambda ([x], excel_round (x, 2)), %o1);` solved the problem. – tilda-a-steiner Mar 04 '22 at 06:57

0 Answers0