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) 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 _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
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 |
"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?" "You can get the desired warning id with the lastwarn function (use it with 2 output arguments)." On 17 February 2017 at 11:28, Oliver Heimlich <[hidden email]> wrote:
_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
On Fri, Feb 17, 2017 at 6:53 AM, Stephen Biggs <[hidden email]> wrote:
_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
In reply to this post by stevebiggs
On Fri, Feb 17, 2017 at 6:00 AM, Stephen Biggs <[hidden email]> wrote: Try these ideas
_______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
In reply to this post by stevebiggs
On Fri, Feb 17, 2017 at 6:00 AM, Stephen Biggs <[hidden email]> wrote: 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) _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
On Fri, Feb 17, 2017 at 10:48 AM, Doug Stewart <[hidden email]> wrote:
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) _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
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 |
On Feb 17, 2017 12:44 PM, "Colin Macdonald" <[hidden email]> 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. _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
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 |
Free forum by Nabble | Edit this page |