Reduce symbolic fraction by powers of ten

5 views (last 30 days)
I have symbolic expression in terms of a primary symbolic variable and 2 auxillary symbolic variables.
The coefficients are as follows:
[a,b] = numden(myfrac(2,1))
coeffs(a)'
coeffs(b)'
shows coefficients for both numerator and denominator in the range of 1e108 to 1e164. I do not seem to be able to get rid of those, not with vpa, also not with simplifyFraction etc. Any suggestions on how to proceed?
Take this as an example:
vpa(1e101*s^2 + 1e106*s + 1e164) / (1e140 * s + 1e112)
  2 Comments
Walter Roberson
Walter Roberson on 3 Mar 2021
syms s
vpa(1e101*s^2 + 1e106*s + 1e164) / (1e140 * s + 1e112)
ans = 
simplify(ans)
ans = 
Seems to be reduced ?
It might help to have your actual expression.
max.s
max.s on 4 Mar 2021
Hi, I've attached a mat file with the sample variable in question. It looks like MATLAB should be able to eliminate a factor 1e81 from both numerator and denominator in component YQ_sym(1,2).

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 5 Mar 2021
load sample;
syms s
G = YQ_sym(1,2);
vpa(G,5)
ans = 
vpa(simplify(G),5)
ans = 
[N,D] = numden(G);
Dc = coeffs(D,s);
FN = factor(N);
NN = prod(FN.*[ones(1,length(FN)-1),1/Dc(end)]);
FD = factor(D);
ND = prod(FD.*[ones(1,length(FD)-1),1/Dc(end)]);
G = vpa(NN/ND, 5)
G = 
vpa(simplify(G),5)
ans = 
Still not really what you would want.
There is a trade-off between making it "nice" and making it general.
It would be possible to analyze each term in terms of products and exponents, and calculate the total exponent, and take the N'th root of the factor Dc(end) and multiply each term inside the exponent by the N'th root. For example the bottom is (s+2) * term^3 so we could calculate a total of exponent of 4, take the 4th root of Dc(end) and multiply (s+2) and (term) by the 4th root, so that overall the product was 1/Dc(end) . This would distribute the factor "fairly" ... but might not really be what you are expecting either.
It isn't obvious what the "best" way would be that also preserves the structure.
It becomes easy if you expand() the numerator and denominator and divide each by Dc(end)
  1 Comment
max.s
max.s on 5 Mar 2021
Thanks for putting the effort in to find a suitable solution. I agree that this problem is somewhat inherently nasty.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!