Why does the SUBS command is not working with numbers?
Show older comments
Hi everyone,
I'm struggling with the subs command: I need to replace all the occurencies of a certain symbolic term "0.8909*Mcf*f" with a symbolic variable called J. If I execute the following line
array_simplified_L = subs(array_simplified, str2sym("0.8909*Mcf*f"),J);
nothing happens, but if I leave out the number and try to subs only "Mcf*f" I manage to do that (i.e. I obtain "0.8909*J"). Is there a problem with numbers and subs command which I am not aware of?
Thanks in advance!
Answers (1)
John D'Errico
on 17 Oct 2022
Edited: John D'Errico
on 17 Oct 2022
Odds are, you don't understand floating point numbers. When you see this value in MATLAB: 0.8909, generally that is not the true value stored internally. All you see is the number, rounded to 4 decimal places. So then, when it goes looking for that value, it does not find it. Essentially, it is looking for EXACTLY that pattern, and it is not to be found, because you only thing 0.8909 is exact.
So it is probably simpler to do the replace as:
array_simplified_L = subs(array_simplified,Mcf*f,J/0.8909);
The net result should be the same.
1 Comment
Francesco Gaudeni
on 17 Oct 2022
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!