Why does the SUBS command is not working with numbers?
이전 댓글 표시
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!
답변 (1개)
John D'Errico
2022년 10월 17일
편집: John D'Errico
2022년 10월 17일
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.
카테고리
도움말 센터 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!