How to show an answer in decimal

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

Answers (1)

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 Comments

It multiplies nominator and denominator by 800, i realise it is the best representation of the result. I want to compare results with answers teacher send us. I don't want to divide each number manualy to see if it is corect. There are many different functions to check
istead of : S = (56*s + 440)/(56*s^3 + 482*s^2 + 337*s + 535)
it is supposed to look like : S = (0.07*s + 0.55)/(0.07*s^3 + 0.6025*s^2 + 0.42125*s + 0.66875)
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.
Thanks a lot i ve wanted it to do that silly thing

Sign in to comment.

Categories

Products

Asked:

on 14 Jan 2022

Commented:

on 15 Jan 2022

Community Treasure Hunt

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

Start Hunting!