how to change the precision of symbolic variables.

1 次查看(过去 30 天)
s^3*246655351680430349161861489360895748665691918000757954295365632i - s^2*(36212255157820456428489768408649977023491870935380775514669056 + 578091697775954585022159881976519846765626019509350787237019648i) - s*(130062300639770074374222879395026417216202027377365642475732992 + 861105664727459103565145461543508318180271162190507702581460992i) - (223478472834610436324352002622703850555766990429849990494534772 + 585856833391770884939511626951491940256735302346867433027453683i)
I need it to be 6 digit precised.

回答(1 个)

Star Strider
Star Strider 2019-10-1
Use the vpa function:
syms s
p = s^3*246655351680430349161861489360895748665691918000757954295365632i - s^2*(36212255157820456428489768408649977023491870935380775514669056 + 578091697775954585022159881976519846765626019509350787237019648i) - s*(130062300639770074374222879395026417216202027377365642475732992 + 861105664727459103565145461543508318180271162190507702581460992i) - (223478472834610436324352002622703850555766990429849990494534772 + 585856833391770884939511626951491940256735302346867433027453683i);
p_vpa = vpa(p, 6)
producing:
p_vpa =
s^3*2.46655e+62i - s^2*(3.62123e+61 + 5.78092e+62i) - s*(1.30062e+62 + 8.61106e+62i) - (2.23478e+62 + 5.85857e+62i)
The expression retains full internal precision, so nothing is lost.
  4 个评论
Sumit dash
Sumit dash 2019-10-1
when we will be using such kind of polynomials for multiple no of times, it is not possible to write everytime this code.
So is there any method where we can declare at the beginning of a program to take only 6 significant digits or 5 significant digits, but not more than that.
Star Strider
Star Strider 2019-10-1
Use the digits function.
If you want to automatically determine what I call the ‘scaling factor’, use this:
scaling_factor = vpa(10.^-fix((log(coeffs(p))/log(10))))
where ‘p’ is your polynomial of interest.
Experiment to get the result you want.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by