Octave Symbolic package: assign `nan` to symfun

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Octave Symbolic package: assign `nan` to symfun

NVS Abhilash
I am using the symbolic package, I have installed `2.5.0` from the source [1]. I get this error in Octave 4.3.0+

```
syms x;
f(x) = nan
error: subscript indices must be integers or boolean
error: called from
    subsindex at line 64 column 5

```

I am a bit confused. Is this expected?
But if I do
```
syms x;
f(x) = nan + x
f(x) = (symfun) nan
```

Maybe Octave cannot identify `f(x) = nan` to be a symfun. But it gets to know that when we do `f(x) = nan + x` because x is a symbol.

Is it a bug, or is it expected?

[1]: https://github.com/cbm755/octsympy
NVS Abhilash
Reply | Threaded
Open this post in threaded view
|

Re: Octave Symbolic package: assign `nan` to symfun

nrjank
On Mon, Feb 6, 2017 at 8:59 AM, NVS Abhilash <[hidden email]> wrote:

> I am using the symbolic package, I have installed `2.5.0` from the source
> [1]. I get this error in Octave 4.3.0+
>
> ```
> syms x;
> f(x) = nan
> error: subscript indices must be integers or boolean
> error: called from
>     subsindex at line 64 column 5
>
> ```
>
> I am a bit confused. Is this expected?
> But if I do
> ```
> syms x;
> f(x) = nan + x
> f(x) = (symfun) nan
> ```
>
> Maybe Octave cannot identify `f(x) = nan` to be a symfun. But it gets to
> know that when we do `f(x) = nan + x` because x is a symbol.
>
> Is it a bug, or is it expected?

Whether or not it's expected, this is 'compatible' behavior.  In Matlab 2016b:

>> syms x
>> f(x) = nan
Error using sym/subsindex (line 769)
Invalid indexing or function definition. When defining a function,
ensure that the arguments are symbolic variables and the body of the
function is a SYM expression. When indexing, the input must be
numeric, logical, or ':'.

>> syms x
>> f(x) = nan + x

f(x) =

NaN

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Octave Symbolic package: assign `nan` to symfun

Colin Macdonald-2
On 06/02/17 07:17, Nicholas Jankowski wrote:
> On Mon, Feb 6, 2017 at 8:59 AM, NVS Abhilash <[hidden email]> wrote:
>> I am using the symbolic package, I have installed `2.5.0` from the source
>> [1]. I get this error in Octave 4.3.0+
 >>
>> Is it a bug, or is it expected?
>
> Whether or not it's expected, this is 'compatible' behavior.  In Matlab 2016b:

I think its a least somewhat expected.  The same "problem" can be seen
without the nan:

syms x
clear f     % (different behavior if f already exists)
f(x) = 7

The way to do this sort of thing is:

f(x) = sym(7)
f(x) = sym(nan)

I think there is not much we can do because Octave (and Matlab I expect)
do not call `@sym/subsasgn` in this case.  We could document it as a
"gotcha" in "help symfun": pull request welcome.

Actually, perhaps `@sym/subindex` could detect when its passed a Symbol
and say something like:

   error ('are you perhaps trying to make a symfun from a non-sym rhs
object?  If so, try using "f(x) = sym(<rhs>)"')

If you're not sure how to do these patches, you could file a bug at
https://github.com/cbm755/octsympy/issues

cheers,
Colin

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave