why use symbolic variables over others
3 次查看(过去 30 天)
显示 更早的评论
Hello I am new to matlab and am working through a book by Huei Huang Lee called Programming with Matlab 2016. In his examples he declares variables and uses them. Then proceeds to declare variables as syms and uses those with no clear explanation as to why I would choose one over the other, which is better, etc. ...
e.g.: syms v0
vs.
v0=5.0
I checked the documentation and there didn't seem to be much there either.
Can anyone shed some light on this please?
Thank you! -Caolan
回答(1 个)
Jyotish Robin
2017-1-20
编辑:Jyotish Robin
2017-1-20
Symbolic numbers are exact representations, unlike floating-point numbers.You can create symbolic numbers by using "sym". The symbolic number is represented in exact rational form, while the floating-point number is a decimal approximation. The symbolic result is not indented, while the standard MATLAB result is indented.
For example:
>>sym(1/3) %returns exact representation
1/3
>>1/3 %returns approximation
.3333
Here the symbolic number is represented in exact rational form, while the floating-point number is a decimal approximation. The symbolic result is not indented, while the standard MATLAB result is indented.
To get an overview of symbolic and numeric arithmetic, refer below link:
Hope it helps!!
2 个评论
Walter Roberson
2017-1-20
You can have symbolic decimal numbers that are not represented as rationals.
Jyotish Robin
2017-1-20
Yea. That statement was specific to the example I mentioned. I will edit. Thank you for pointing out. :)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!