How to change code to avoid the warning from floating-point and symbolic?

Hello,

I just discovered Octave and I’m liking it a lot, mainly because it’s open source free and because almost all of my code from Matlab can be used here without change being needed.

I’d like to ask colleagues support in order to fix my code to avoid warning from symbolic package as indicated below.

Warning: passing floating-point values to sym is dangerous, see “help sym”.

Below the minimum part of the code to reproduce the warning.

``````M=sym('M');
CC=0.3;
AX=2.3430;  % AX comes form a equation, but i'm putting a number here as example.
DCC=diff(-sqrt(CC^2-(M-AX).^2));
``````

How could I change the DDC expression to get the same result and avoid the warning from symbolic package?

The symbolic package tries to be “nice” to the user, avoiding the illusion that converting an approximated floating-point number can be magically converted into a symbolic (infinite precise) value.

``````help sym
``````

``````syms M
CC = sym (3) / 10;
AX = sym (2.3430, 'f');  % AX comes form a equation, but i'm putting a number here as example.
DCC = diff(-sqrt(CC^2-(M-AX).^2));
``````

For the impatient hackers: in Octave there is a general mechanism to avoid particular warnings you know about the issue and and simply do not want to see it anymore.

``````% Trigger the annoying warning
DCC=diff(-sqrt(CC^2-(M-AX).^2));
warning: passing floating-point values to sym is dangerous, see "help sym"
[...]

% Deactivate a particular annoying warning
[~, id] = lastwarn ()
id = OctSymPy:sym:rationalapprox
S = warning ('off', id);

% Now runs without warning
DCC=diff(-sqrt(CC^2-(M-AX).^2));

% Restore previous warning state
warning (S)
DCC=diff(-sqrt(CC^2-(M-AX).^2));
warning: passing floating-point values to sym is dangerous, see "help sym"
[...]
``````

thanks for posting siko1056

I tried to read the manuals many times but wasn’t able to find a way that fits my case, I tried also to find more explanations in the internet without success too, so I asked for help here once some colleagues with more experience could suggest a better approach or maybe confirms that in this case there is no solution and i need to leave with the warning.

Once the equation is related to a mechanical device with spherical shape 4 decimals value is more then enough so symbolic conversion won’t be a problem once it used much more then 4 decimals.

http://wiki.octave.org/Symbolic_package

1 Like

You are welcome. Enjoy using Octave and the symbolic toolbox and ask any question you like here

If your issue is solved, you can mark this item as such