How to show an answer in decimal

조회 수: 55 (최근 30일)
Andrzej Malczyk
Andrzej Malczyk 2022년 1월 14일
댓글: Andrzej Malczyk 2022년 1월 15일
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

답변 (1개)

John D'Errico
John D'Errico 2022년 1월 14일
편집: John D'Errico 2022년 1월 14일
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
John D'Errico
John D'Errico 2022년 1월 15일
편집: John D'Errico 2022년 1월 15일
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.
Andrzej Malczyk
Andrzej Malczyk 2022년 1월 15일
Thanks a lot i ve wanted it to do that silly thing

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by