octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave 3.2.4 - Error Calculating Powers of 2


From: Martin Helm
Subject: Re: Octave 3.2.4 - Error Calculating Powers of 2
Date: Thu, 17 Mar 2011 15:14:57 +0100
User-agent: KMail/1.13.6 (Linux/2.6.34.7-0.7-desktop; KDE/4.6.1; x86_64; ; )

Am Donnerstag, 17. März 2011, 07:47:34 schrieb Vickreman Chettiar:
> Hi.
> 
>   I have recently installed Octave, and I am trying to calculate the powers
> of two from 1 to 50 with the following code.
> *n=1:50; m=2^n; disp(m)*
> I keep getting the following error
> *error: for x^A, A must be square*
> and have not so far been able to perform the calculation in Octave.
> 
>   I see no reason why *A* has to be square, and I have checked the manual
> and confirmed that *^* is indeed the symbol for exponentiation. Am I doing
> something incorrectly, or is this a bug? How do I fix the problem?
> 
> I am using version 3.2.4 of Octave. My operating-system is the 64-bit
> version of Microsoft Windows 7 Professional Edition.
> 
>   Thank you and regards, Vickreman.

It is really simply:

n=1:50 is a vector (so it is a matrix) and if you use ^2 it tries to calculate 
the 2nd power of the matrix which is not possible if it is not square.
What you want is the componentwise calculation which is done with .^ (ther is 
a dot in front of ^).

n=1:50; m=2.^n; disp(m)

will do it.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]