# How to show an answer in decimal

5 views (last 30 days)
Andrzej Malczyk on 14 Jan 2022
Commented: Andrzej Malczyk on 15 Jan 2022
I want to obtain simplified equation,
a = 0.25;
b = 0.5;
T = 0.07;
k1 = 0.6;
k2 = 0.55;
k3 = 1;
syms s ;
expr =(T.*s+k2)./(T.*s.*(s+a).*(s+b)+k2.*(s+a).*(s+b)+k1*k3)
that part of code just rewrite the answer with numbers instead of variables, then i found command S = simplify(expr) which sort of worked, denominator is in polynomial form, howewer it also simplified it in a way i didnt want to : S =(56*s + 440)/(56*s^3 + 482*s^2 + 337*s + 535).
Another command sympref('FloatingPointOutput',true) worked for expr but didnt work for S
code:
a = 0.25;
b = 0.5;
T = 0.07;
k1 = 0.6;
k2 = 0.55;
k3 = 1;
sympref('FloatingPointOutput',true)
syms s ;
expr =(T.*s+k2)./(T.*s.*(s+a).*(s+b)+k2.*(s+a).*(s+b)+k1*k3)
sympref('FloatingPointOutput',true)
S =simplify(expr)
I want it to show S in decimal
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (1)

John D'Errico on 14 Jan 2022
Edited: John D'Errico on 14 Jan 2022
a = 0.25;
b = 0.5;
T = 0.07;
k1 = 0.6;
k2 = 0.55;
k3 = 1;
sympref('FloatingPointOutput',true)
ans = logical
1
syms s ;
expr =(T.*s+k2)./(T.*s.*(s+a).*(s+b)+k2.*(s+a).*(s+b)+k1*k3)
expr =
sympref('FloatingPointOutput',true)
ans = logical
1
S =simplify(expr)
S =
What decimals do you want? S is essentially a FUNCTION of the variable s. There is nothing that floating point can do for you. The only numbers in that expression are all integers, as coefficients of the rational polynomial result.
If you substitute a numeric value for s, then the result will be a number.
subs(S,s,2)
ans =
0.1540
But this is not what you asked. You said you want to obtain a simplified equation. But that is about as simple as it gets. Could you find a partial fraction version of that form? Well yes. But it hardly looks simpler to me, since two of the roots of the denominator cubic polynomial are complex.
partfrac(S,s,'factormode','complex')
ans =
##### 3 CommentsShowHide 2 older comments
Andrzej Malczyk on 15 Jan 2022
Thanks a lot i ve wanted it to do that silly thing

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!