help-octave
[Top][All Lists]

## Re: Symbolic expand function doesn't always do anything

 From: Benjamin Sapp Subject: Re: Symbolic expand function doesn't always do anything Date: 13 Sep 2004 10:01:39 -0600

```Hi,

Indeed, you are correct it is an octave integration peculiarity.  You
see, octave interprets any thing that can be a number as a double
first.  Then, when a double is used in a symbolic expression it is
converted to the exact form like in ginsh.  By that time it's too late
because a 1 is already double approximation of a 1 rather than exactly a
1.   You can perform your example from ginsh in octave by surrounding
each exact number with quotes and vpa().  For example on my computer:

octave:47> expand( (x-vpa("1"))^vpa("3"))
ans =

-1+x^3-3*x^2+3*x

It's a bit cumbersome but I don't think there's a better solution.

Good luck,
Ben.

On Mon, 2004-09-13 at 08:28, edA-qa mort-ora-y wrote:
> I'm using the OctaveForge integration of the GiNaC symbolic library and
> having some trouble using the "expand" function.
>
> I want is to perform the polynomial expansion:
>
>       >x = sym( "x" )
>       >expand( (x-1)^2 )
>       ans = (x-1)^2
>
>       I want to get
>       ans = 1 + x^2 - 2*x
>
> If you do this form, it works:
>       >expand( (x-1) * (x-1) )
>       ans = 1.0+x^2-(2.0)*x
>
> Using ginsh with expand produces the desired results, so I'm assuming it
> is an Octave integration peculariaty:
>
>       ginsh>  expand( (x-1)^3 );
>       -1-3*x^2+x^3+3*x
>

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```