From: Arthur N. <ac...@ca...> - 2024-02-24 09:47:50
|
I am not aware of anything built in that deals with that instantly. I might start with symbolic procedure killsmall v; begin prin2 "killsmall "; print v; % I will need to do things here! return v end; symbolic operator killsmall; on rounded; killsmall (a + 1.0e-4*b + 1.0e-6c + 1.0e-8*d); and there you will see that the input expression has been reduced to a "nice" prefix form. So where it says "need to do" I might next try v := kill v; with symbolic procedure kill v; if floatp v and v <= 1.0e-6 then 0.0 else if atom v then v else kill car v . kill cdr v; where then I see killsmall (a + 1.0e-4*b + 1.0e-6c + 1.0e-8*d); killsmall (plus a (times (!:rd!: . 0.0001) b) (times (!:rd!: . 1.0e-06) c) ( times (!:rd!: . 1.0e-08) d)) a + 0.0001*b and of course once you are confident you can remove the print trace statement - but I suggest you leave that in to start in case odd things happen. What I do here is maybe a bit evil generating (!:rd!: . 0.0) as an explicit zero that I hope gets tidied away later. Also if your expressions became huge the recursion in my kill function could lead to stack overflow which could probably be avoided by messier code... Arthur On Sat, 17 Feb 2024, Prof Tony Roberts via Reduce-algebra-developers wrote: > Hi all, > > I am doing a mixed numerical-algebraic problem via iteration, an > iteration that needs to stop once numerical coefficients are small. > Is there a function in reduce that will go through an expression and > set to zero all coefficients that are less than some tolerance? (I > cannot find anything in the manual.) > > For example, after some iterations I have the following expressions > and I would like to zero every coefficient of magnitude less than > 1e-6 say. So that then the pde becomes a zero vector, and the dudt > expressions simplify to just the significant terms. > > **** ITERATION 14 > pde := mat((0.0000002622*df(uu(1),x)*d - 0.00000001295*df(uu(2),x)*d), > ( - 0.0000003978*df(uu(1),x)*d + > 0.00000006401*df(uu(2),x)*d), > ( - 1.438e-14*uu(1) - 0.00000003801*df(uu(1),x)*d > - 0.00000005106*df(uu(2),x)*d), > (0.00000003801*df(uu(1),x)*d - 0.00000005106*df(uu(2),x)*d), > (0.0000003978*df(uu(1),x)*d + 0.00000006401*df(uu(2),x)*d), > ( - 1.952e-16*uu(1) - 0.0000002622*df(uu(1),x)*d > - 0.00000001295*df(uu(2),x)*d)) > normpde := 0.0000003978 > dudt(0) := 9.939e-15*uu(1) + 3.875e-15*uu(2) + 6.98e-15*df(uu(0),x)*d > - 5.402e-15*df(uu(1),x)*d + 0.6336*df(uu(2),x)*d > dudt(1) := - 0.8371*uu(1) + 3.31e-15*uu(2) + 1.45e-15*df(uu(0),x)*d > - 3.216e-14*df(uu(1),x)*d + 1.505*df(uu(2),x)*d > > Tony > |