|
From: Dimiter P. <dim...@gm...> - 2014-09-29 17:31:07
|
Hello, I define a function dy(y):=if y#0 and y#0.0 then 1/(2*y) else 'nan; Then I wanted to substitute it's first argument by a value. The idea is to use pass a function having a variable number of arguments as a method parameter and then to evaluate it only on certain arguments. I stumbled on the following weird behavior: apply(dy, [y=0]); expt: undefined: 0 to a negative exponent. -- an error. also here at(dy(y),[y=0]); expt: undefined: 0 to a negative exponent. -- an error. while dy(0) correctly evaluates to 'nan best regards, Dimiter |
|
From: Gunter K. <gu...@pe...> - 2014-09-29 17:39:38
|
Try using equals(y,0) as criterion of the comparison: "=" tests for structural equality and there are several ways of expressing zero. Kind regards, Gunter. On 29. September 2014 19:30:31 MESZ, Dimiter Prodanov <dim...@gm...> wrote: >Hello, > >I define a function > >dy(y):=if y#0 and y#0.0 then 1/(2*y) else 'nan; > >Then I wanted to substitute it's first argument by a value. The idea is >to >use pass a function having a variable number of arguments as a method >parameter and then to evaluate it only on certain arguments. > > >I stumbled on the following weird behavior: > >apply(dy, [y=0]); >expt: undefined: 0 to a negative exponent. > -- an error. > >also here > >at(dy(y),[y=0]); > >expt: undefined: 0 to a negative exponent. > -- an error. > >while dy(0) correctly evaluates to 'nan > >best regards, > >Dimiter > > >------------------------------------------------------------------------ > >------------------------------------------------------------------------------ >Slashdot TV. Videos for Nerds. Stuff that Matters. >http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk > >------------------------------------------------------------------------ > >_______________________________________________ >Maxima-discuss mailing list >Max...@li... >https://lists.sourceforge.net/lists/listinfo/maxima-discuss -- Diese Nachricht wurde von meinem Mobiltelefon mit Kaiten Mail gesendet. |
|
From: Kris K. <kat...@gm...> - 2014-09-29 18:09:37
|
Hi Dimiter, On 09/29/2014 12:30 PM, Dimiter Prodanov wrote: > Hello, > > I define a function > > dy(y):=if y#0 and y#0.0 then 1/(2*y) else 'nan; > > Then I wanted to substitute it's first argument by a value. The idea is > to use pass a function having a variable number of arguments as a method > parameter and then to evaluate it only on certain arguments. > > > I stumbled on the following weird behavior: > > apply(dy, [y=0]); > expt: undefined: 0 to a negative exponent. > -- an error. > The list given to apply shouldn't include the parameter name; what's happening is that the equation "y=0" is getting passed to dy and that's causing the problem. (%i3) trace(dy)$ (%i4) apply(dy,[y=0]); 1 Enter dy [y = 0] expt: undefined: 0 to a negative exponent. #0: A traced function(y=y = 0) -- an error. To debug this try: debugmode(true); (%i5) apply(dy,[0]); 1 Enter dy [0] 1 Exit dy nan (%o5) nan > also here > > at(dy(y),[y=0]); > > expt: undefined: 0 to a negative exponent. > -- an error. > Here the problem is that dy(y) is evaluated before the y=0 is done. (%i6) at(dy(y),[y=0]); 1 Enter dy [y] 1 Exit dy 1/(2*y) expt: undefined: 0 to a negative exponent. -- an error. To debug this try: debugmode(true); I hope this helps. Cheers, Kris Katterjohn |
|
From: Stavros M. (Σ. Μ. <mac...@al...> - 2014-09-29 18:10:28
|
You are calling dy(y=0). I think you want to call dy(0). On Mon, Sep 29, 2014 at 1:30 PM, Dimiter Prodanov <dim...@gm...> wrote: > Hello, > > I define a function > > dy(y):=if y#0 and y#0.0 then 1/(2*y) else 'nan; > > Then I wanted to substitute it's first argument by a value. The idea is to > use pass a function having a variable number of arguments as a method > parameter and then to evaluate it only on certain arguments. > > > I stumbled on the following weird behavior: > > apply(dy, [y=0]); > expt: undefined: 0 to a negative exponent. > -- an error. > > also here > > at(dy(y),[y=0]); > > expt: undefined: 0 to a negative exponent. > -- an error. > > while dy(0) correctly evaluates to 'nan > > best regards, > > Dimiter > > > > > > > ------------------------------------------------------------------------------ > Slashdot TV. Videos for Nerds. Stuff that Matters. > > http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > > |
|
From: Dimiter P. <dim...@gm...> - 2014-09-29 19:39:53
|
Hello, I tried this particular syntax because I want to pass named arguments. In my hypothesis some of the arguments may not have been assigned. i.e. for a function f(x,y,z,w) I would like to pass only for example [x=1, z=2] in the code. I don't know if this is possible in Maxima. at and apply looked like good candidates for this scenario. best regards, Dimiter |
|
From: Stavros M. (Σ. Μ. <mac...@al...> - 2014-09-29 19:48:17
|
Maxima does not support named arguments.
Instead of using functions and function application, you might want to use
expressions and evaluation, like this:
dy: if not equal(y,0) then 1/(2*y) else 'nan$
ev(dy,[y=0]);
Unfortunately, 'subst' does not work here, because it will try to simplify
the expression 1/0, which gives an error.
-s
On Mon, Sep 29, 2014 at 3:39 PM, Dimiter Prodanov <dim...@gm...>
wrote:
> Hello,
>
> I tried this particular syntax because I want to pass named arguments.
> In my hypothesis some of the arguments may not have been assigned.
>
> i.e. for a function f(x,y,z,w) I would like to pass only for example
> [x=1, z=2] in the code.
>
> I don't know if this is possible in Maxima. at and apply looked like good
> candidates for this scenario.
>
> best regards,
>
> Dimiter
>
|
|
From: Kris K. <kat...@gm...> - 2014-09-29 22:20:32
|
On 09/29/2014 02:39 PM, Dimiter Prodanov wrote: > Hello, > > I tried this particular syntax because I want to pass named arguments. > In my hypothesis some of the arguments may not have been assigned. > > i.e. for a function f(x,y,z,w) I would like to pass only for example > [x=1, z=2] in the code. > > I don't know if this is possible in Maxima. at and apply looked like > good candidates for this scenario. > Maybe you want to use an assoc list: (%i2) f([args]) := map(lambda([x], assoc(x, args)), ['a,'b,'c,'d])$ (%i3) f(c=charlie,a=alpha); (%o3) [alpha,false,charlie,false] Cheers, Kris Katterjohn |
|
From: Robert D. <rob...@gm...> - 2014-09-30 02:21:35
|
On 2014-09-29, Dimiter Prodanov <dim...@gm...> wrote: > I tried this particular syntax because I want to pass named arguments. > In my hypothesis some of the arguments may not have been assigned. > > i.e. for a function f(x,y,z,w) I would like to pass only for example [x=1, > z=2] in the code. Here's one way. ev(f(x, y, z, w), [x = 1, z = 2]); => f(1, y, 2, w) > I don't know if this is possible in Maxima. at and apply looked like > good candidates for this scenario. 'at' works too. But note that the syntax is different from what you tried before. at(f(x, y, z, w), [x = 1, z = 2]); => f(1, y, 2, w) Note also you can construct 'at(...) noun expressions. best Robert Dodier |
|
From: Richard F. <fa...@be...> - 2014-09-30 03:18:25
|
If you want to use keyword parameters, the following construct will work, assuming you are not messing with using the keyword parameter names in the global context, like giving them values. instead of f(alpha,beta,gamma) := alpha+beta-3*gamma you can do g([args]):= subst(args, alpha+beta-3*gamma) and then use g(alpha=3,gamma=4) to get beta-9. Note that keyword parameter beta is not set, so it is left as just beta. It would be unfortunate if you set, globally alpha:45, say. Unless you meant to do that. RJF On 9/29/2014 7:21 PM, Robert Dodier wrote: > On 2014-09-29, Dimiter Prodanov <dim...@gm...> wrote: > >> I tried this particular syntax because I want to pass named arguments. >> In my hypothesis some of the arguments may not have been assigned. >> >> i.e. for a function f(x,y,z,w) I would like to pass only for example [x=1, >> z=2] in the code. > Here's one way. > > ev(f(x, y, z, w), [x = 1, z = 2]); > => f(1, y, 2, w) > >> I don't know if this is possible in Maxima. at and apply looked like >> good candidates for this scenario. > 'at' works too. But note that the syntax is different from what you > tried before. > > at(f(x, y, z, w), [x = 1, z = 2]); > => f(1, y, 2, w) > > Note also you can construct 'at(...) noun expressions. > > best > > Robert Dodier > > > ------------------------------------------------------------------------------ > Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer > Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports > Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper > Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer > http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss |