Quantcast

Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

stevebiggs
Hi,

I am using the symbolic package (so include `pkg load symbolic` before the following commands if necessary). If I run:

    syms x
    fsym = x * cos(x)
    fsymder = diff(fsym)
    vpa(subs(fsymder, x, 3.141592654), 8)

Then I get the following:

    warning: Using rat() heuristics for double-precision input (is this what you wanted?)
    warning: called from
        sym at line 256 column 9
        subs at line 118 column 7
    ans = (sym) -1.0000000

So the answer is correct but there is that warning about rat() heuristics. How can I fix it so that the warning is not given. NB: I would rather **fix** the code so that the warning is not raised rather than just supressing the warning with `warning('off', '<warning_id>')`. However, if the former is not possible, then I will accept the latter but I need to know the warning ID.

Many thanks,
Steve




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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Oliver Heimlich
Am 17. Februar 2017 12:00:50 MEZ schrieb Stephen Biggs <[hidden email]>:

>Hi,
>
>I am using the symbolic package (so include `pkg load symbolic` before
>the
>following commands if necessary). If I run:
>
>    syms x
>    fsym = x * cos(x)
>    fsymder = diff(fsym)
>    vpa(subs(fsymder, x, 3.141592654), 8)
>
>Then I get the following:
>
>    warning: Using rat() heuristics for double-precision input (is this
>what you wanted?)
>    warning: called from
>        sym at line 256 column 9
>        subs at line 118 column 7
>    ans = (sym) -1.0000000
>
>So the answer is correct but there is that warning about rat()
>heuristics.
>How can I fix it so that the warning is not given. NB: I would rather
>**fix** the code so that the warning is not raised rather than just
>supressing the warning with `warning('off', '<warning_id>')`. However,
>if
>the former is not possible, then I will accept the latter but I need to
>know the warning ID.
>
>Many thanks,
>Steve

I guess the warning is caused by your numeric literal 3.141592654 in the code.

In Octave this would normally result in an approximation of this value in double precision. However, the symbolic package detects this and suggests that you should explicitly create a symbolic value for 3.141592654 with the desired conversion semantics that you intend. Do you want to use the exact decimal value 3.141592654 or do you want to use an approximation?

You can get the desired warning id with the lastwarn function (use it with 2 output arguments).

Oliver

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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

stevebiggs
"I guess the warning is caused by your numeric literal 3.141592654 in the code."

Yes, indeed it is. If I use, say, 0 instead, then there is no warning.

"Do you want to use the exact decimal value 3.141592654 or do you want to use an approximation?"

I'm not really bothered. The value given is just an example. In my production code I have a section before the symbolic stuff where some values are worked out and stored as doubles. I then want to use these in place of that value. I don't care whether they use the exact value or an approximation. I just want it to use whatever and do so without a warning.

So, I guess I'm looking for an option to subs or vpa that basically says "just use this value however you see fit and keep quiet about it".

"You can get the desired warning id with the lastwarn function (use it with 2 output arguments)."

Thanks, I will try that.

S




On 17 February 2017 at 11:28, Oliver Heimlich <[hidden email]> wrote:
Am 17. Februar 2017 12:00:50 MEZ schrieb Stephen Biggs <[hidden email]>:
>Hi,
>
>I am using the symbolic package (so include `pkg load symbolic` before
>the
>following commands if necessary). If I run:
>
>    syms x
>    fsym = x * cos(x)
>    fsymder = diff(fsym)
>    vpa(subs(fsymder, x, 3.141592654), 8)
>
>Then I get the following:
>
>    warning: Using rat() heuristics for double-precision input (is this
>what you wanted?)
>    warning: called from
>        sym at line 256 column 9
>        subs at line 118 column 7
>    ans = (sym) -1.0000000
>
>So the answer is correct but there is that warning about rat()
>heuristics.
>How can I fix it so that the warning is not given. NB: I would rather
>**fix** the code so that the warning is not raised rather than just
>supressing the warning with `warning('off', '<warning_id>')`. However,
>if
>the former is not possible, then I will accept the latter but I need to
>know the warning ID.
>
>Many thanks,
>Steve

I guess the warning is caused by your numeric literal 3.141592654 in the code.

In Octave this would normally result in an approximation of this value in double precision. However, the symbolic package detects this and suggests that you should explicitly create a symbolic value for 3.141592654 with the desired conversion semantics that you intend. Do you want to use the exact decimal value 3.141592654 or do you want to use an approximation?

You can get the desired warning id with the lastwarn function (use it with 2 output arguments).

Oliver


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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Doug Stewart-4
There are some examples at

that might help you.



On Fri, Feb 17, 2017 at 6:53 AM, Stephen Biggs <[hidden email]> wrote:
"I guess the warning is caused by your numeric literal 3.141592654 in the code."

Yes, indeed it is. If I use, say, 0 instead, then there is no warning.

"Do you want to use the exact decimal value 3.141592654 or do you want to use an approximation?"

I'm not really bothered. The value given is just an example. In my production code I have a section before the symbolic stuff where some values are worked out and stored as doubles. I then want to use these in place of that value. I don't care whether they use the exact value or an approximation. I just want it to use whatever and do so without a warning.

So, I guess I'm looking for an option to subs or vpa that basically says "just use this value however you see fit and keep quiet about it".

"You can get the desired warning id with the lastwarn function (use it with 2 output arguments)."

Thanks, I will try that.

S




On 17 February 2017 at 11:28, Oliver Heimlich <[hidden email]> wrote:
Am 17. Februar 2017 12:00:50 MEZ schrieb Stephen Biggs <[hidden email]>:
>Hi,
>
>I am using the symbolic package (so include `pkg load symbolic` before
>the
>following commands if necessary). If I run:
>
>    syms x
>    fsym = x * cos(x)
>    fsymder = diff(fsym)
>    vpa(subs(fsymder, x, 3.141592654), 8)
>
>Then I get the following:
>
>    warning: Using rat() heuristics for double-precision input (is this
>what you wanted?)
>    warning: called from
>        sym at line 256 column 9
>        subs at line 118 column 7
>    ans = (sym) -1.0000000
>
>So the answer is correct but there is that warning about rat()
>heuristics.
>How can I fix it so that the warning is not given. NB: I would rather
>**fix** the code so that the warning is not raised rather than just
>supressing the warning with `warning('off', '<warning_id>')`. However,
>if
>the former is not possible, then I will accept the latter but I need to
>know the warning ID.
>
>Many thanks,
>Steve

I guess the warning is caused by your numeric literal 3.141592654 in the code.

In Octave this would normally result in an approximation of this value in double precision. However, the symbolic package detects this and suggests that you should explicitly create a symbolic value for 3.141592654 with the desired conversion semantics that you intend. Do you want to use the exact decimal value 3.141592654 or do you want to use an approximation?

You can get the desired warning id with the lastwarn function (use it with 2 output arguments).

Oliver


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




--
DASCertificate for 206392


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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Doug Stewart-4
In reply to this post by stevebiggs


On Fri, Feb 17, 2017 at 6:00 AM, Stephen Biggs <[hidden email]> wrote:
Hi,

I am using the symbolic package (so include `pkg load symbolic` before the following commands if necessary). If I run:

    syms x
    fsym = x * cos(x)
    fsymder = diff(fsym)
    vpa(subs(fsymder, x, 3.141592654), 8)

Then I get the following:

    warning: Using rat() heuristics for double-precision input (is this what you wanted?)
    warning: called from
        sym at line 256 column 9
        subs at line 118 column 7
    ans = (sym) -1.0000000

So the answer is correct but there is that warning about rat() heuristics. How can I fix it so that the warning is not given. NB: I would rather **fix** the code so that the warning is not raised rather than just supressing the warning with `warning('off', '<warning_id>')`. However, if the former is not possible, then I will accept the latter but I need to know the warning ID.

Many thanks,
Steve



Try these ideas

 syms x
    fsym = x * cos(x)
    fsymder = diff(fsym)
    
    xx=sym(pi)
    
    xxx=sym( "3.14159");
    
    
    syms q
    q=2.777123
    qq=mat2str(q)
    ww=sym(qq)
    
    vpa(subs(fsymder, x, xx), 8)


--
DASCertificate for 206392


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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Doug Stewart-4
In reply to this post by stevebiggs


On Fri, Feb 17, 2017 at 6:00 AM, Stephen Biggs <[hidden email]> wrote:
Hi,

I am using the symbolic package (so include `pkg load symbolic` before the following commands if necessary). If I run:

    syms x
    fsym = x * cos(x)
    fsymder = diff(fsym)
    vpa(subs(fsymder, x, 3.141592654), 8)

Then I get the following:

    warning: Using rat() heuristics for double-precision input (is this what you wanted?)
    warning: called from
        sym at line 256 column 9
        subs at line 118 column 7
    ans = (sym) -1.0000000

So the answer is correct but there is that warning about rat() heuristics. How can I fix it so that the warning is not given. NB: I would rather **fix** the code so that the warning is not raised rather than just supressing the warning with `warning('off', '<warning_id>')`. However, if the former is not possible, then I will accept the latter but I need to know the warning ID.

Many thanks,
Steve



I am thinking of putting this on the wiki. 

## Demo of how to use a number (which was calculated in octave
## variables) in a symbolic calculation.

## use octave to calculate some number:
 a=pi/2

## now do some work with the symbolic pkg
 syms x
    f = x * cos(x)
    df = diff(fsym)

## Next get the number into a symbolic variable   
## convert to string first  
    aa=mat2str(a)
## and now to a symbolic variable.    
    ww=sym(aa)
## and now use it  
    vpa(subs(df, x, ww), 28)



Dopes that answer your question?

 


DASCertificate for 206392



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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Doug Stewart-4


On Fri, Feb 17, 2017 at 10:48 AM, Doug Stewart <[hidden email]> wrote:


On Fri, Feb 17, 2017 at 6:00 AM, Stephen Biggs <[hidden email]> wrote:
Hi,

I am using the symbolic package (so include `pkg load symbolic` before the following commands if necessary). If I run:

    syms x
    fsym = x * cos(x)
    fsymder = diff(fsym)
    vpa(subs(fsymder, x, 3.141592654), 8)

Then I get the following:

    warning: Using rat() heuristics for double-precision input (is this what you wanted?)
    warning: called from
        sym at line 256 column 9
        subs at line 118 column 7
    ans = (sym) -1.0000000

So the answer is correct but there is that warning about rat() heuristics. How can I fix it so that the warning is not given. NB: I would rather **fix** the code so that the warning is not raised rather than just supressing the warning with `warning('off', '<warning_id>')`. However, if the former is not possible, then I will accept the latter but I need to know the warning ID.

Many thanks,
Steve



I am thinking of putting this on the wiki. 

## Demo of how to use a number (which was calculated in octave
## variables) in a symbolic calculation.

## use octave to calculate some number:
 a=pi/2

## now do some work with the symbolic pkg
 syms x
    f = x * cos(x)
    df = diff(fsym)

## Next get the number into a symbolic variable   
## convert to string first  
    aa=mat2str(a)
## and now to a symbolic variable.    
    ww=sym(aa)
## and now use it  
    vpa(subs(df, x, ww), 28)



Dopes that answer your question?

 




There was an error. this is better


## Demo of how to use a number (which was calculated in an octave
## variable) in a symbolic calculation, without getting a warning.

## use octave to calculate some number:
 a=pi/2

## now do some work with the symbolic pkg
 syms x
    f = x * cos(x)
    df = diff(f)

## Next get the number into a symbolic variable   
## convert to string first  
    aa=mat2str(a)
## and now to a symbolic variable.    
    ww=sym(aa)
## and now use it  
    vpa(subs(df, x, ww), 28)

--
DAS


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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Colin Macdonald-2
On 17/02/17 08:18, Doug Stewart wrote:
>     I am thinking of putting this on the wiki.

Good idea!  I can help edit.

But first, the essential pattern here is:

1.  Do a symbolic calculation (in this case, a derivative)
2.  Evaluate that result for double values.

"subs" is not really the right tool for this.  It makes symbolic
substitutions.

Perhaps the right pattern here is:

 >> df = diff(...)
 >> dfh = function_handle(df)
 >> dfh(3.1415927)

Here "dfh" is a regular plain-old Octave anonymous function, can be
evaluated efficiently for doubles, etc.

Note: you can also write this as "dfh = matlabFunction(df)" for
compatibility with the Matlab Symbolic Toolbox.

There is some discussion about all this in
https://github.com/cbm755/octsympy/issues/121

cheers,
Colin


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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Doug Stewart-4


On Feb 17, 2017 12:44 PM, "Colin Macdonald" <[hidden email]> wrote:
On 17/02/17 08:18, Doug Stewart wrote:
    I am thinking of putting this on the wiki.

Good idea!  I can help edit.

But first, the essential pattern here is:

1.  Do a symbolic calculation (in this case, a derivative)
2.  Evaluate that result for double values.

"subs" is not really the right tool for this.  It makes symbolic substitutions.

Perhaps the right pattern here is:

>> df = diff(...)
>> dfh = function_handle(df)
>> dfh(3.1415927)

Here "dfh" is a regular plain-old Octave anonymous function, can be evaluated efficiently for doubles, etc.

Note: you can also write this as "dfh = matlabFunction(df)" for compatibility with the Matlab Symbolic Toolbox.

There is some discussion about all this in https://github.com/cbm755/octsympy/issues/121

cheers,
Colin


I already did the wiki before I saw this.
If you want  to change it go-ahead, if you want me to change something then let me know. 

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

Re: Symbolica package warning: Using rat() heuristics for double-precision input (is this what you wanted?)

Colin Macdonald-2
On 17/02/17 11:14, Doug Stewart wrote:
> I already did the wiki before I saw this.
> If you want  to change it go-ahead, if you want me to change something
> then let me know.

Thanks for [doing that](https://wiki.octave.org/Symbolic_package)

I edited it and moved it to the top, as probably more relevant then some
of the more advanced examples.

Colin

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