How to show an answer in decimal
59 views (last 30 days)
Show older comments
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 Comments
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)
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)
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)
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')
3 Comments
John D'Errico
on 15 Jan 2022
Edited: John D'Errico
on 15 Jan 2022
This is an arbitrary factor of 800 times both numerator and denominator. In fact, it is much more correct than what you are asking to see, since floating point numbers, written to only a few significant digits, are rarely exactly correct.
I suppose you can simply enough extract the numerator and denominator polynomials; Then divide each of them by 800, then showing the coefficients in floating point form.
[N,D] = numden(S)
N =
56*s + 440
D =
56*s^3 + 482*s^2 + 337*s + 535
If you wish, since simplify will not be appied to this expression, you could do this:
vpa(N/800)/vpa(D/800)
ans =
(0.0700*s + 0.5500)/(0.0700*s^3 + 0.6025*s^2 + 0.4213*s + 0.6687)
This all seems a bit silly to me, but it does what you want.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!