Dirk Laurie on Tue, 12 May 2015 14:32:12 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: incorrect type in gpow(0,n) (t_VEC) |
2015-02-12 7:33 GMT+02:00 Kevin Acres <research@research-systems.com>: > I've noticed recently that something like [1,2,3]^[2] works fine, Then you have probably also noticed that the result is a vector of one-element floating-point vectors. I'm curious about why anyone would want precisely that. > whereas if any element is zero I get an error: > > ? [0,2,3]^[2] > *** at top-level: [0,2,3]^[2] > *** ^---- > *** _^_: incorrect type in gpow(0,n) (t_VEC). > *** Break loop: type 'break' to go back to GP prompt > > Is there a work around for this? The reason is that floating-point a^b is in effect computed as exp(log(a)*b). log(0) => bang! > As background I need to perform sqrt(vecsum(x^[2])) so maybe there is a > better way of obtaining the same result. I would have expected `norm(x)`, whose help message says "norm(x): norm of x.", to do that, but gp 2.5.5 (which comes with Ubuntu 14.04 LTS) returns [0,4,9] when x=[0,2,3]. Doubtless all will become clear if one peruses the user's manual. sqrt(x*x~) works.