How to show an answer in decimal

36 visualizaciones (últimos 30 días)
Andrzej Malczyk
Andrzej Malczyk el 14 de En. de 2022
Comentada: Andrzej Malczyk el 15 de En. de 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

Respuestas (1)

John D'Errico
John D'Errico el 14 de En. de 2022
Editada: John D'Errico el 14 de En. de 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 comentarios
John D'Errico
John D'Errico el 15 de En. de 2022
Editada: John D'Errico el 15 de En. de 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.
Andrzej Malczyk
Andrzej Malczyk el 15 de En. de 2022
Thanks a lot i ve wanted it to do that silly thing

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by