ans representation in decimal

1 Ansicht (letzte 30 Tage)
Andrew
Andrew am 1 Sep. 2020
Kommentiert: Andrew am 1 Sep. 2020
Good day.
Houp, I could get some hint on how to change the formatting of answers in a live script.
syms ht_inpt(mass, dlt_t, spc_ht_mtr)
ht_inpt(mass, dlt_t, spc_ht_mtr)=mass*dlt_t*spc_ht_mtr;
mass=6*u.kg;
mass_t1=(20+273)*u.K;
mass_t2=(100+273)*u.K;
spc_ht_mtr=4190*u.J/(u.kg*u.K);
dlt_t=mass_t2-mass_t1;
ht_inpt=ht_inpt(mass, dlt_t, spc_ht_mtr)
ht_inpt=2011200 J
ht_inpt = unitConvert(ht_inpt,u.kJ)
ht_inpt=10056/5 kJ
­How a document can be edited that all answers in it would be expressed with decimals?

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 1 Sep. 2020
Bearbeitet: Cris LaPierre am 1 Sep. 2020
FYI the code you shared generates the following error
Unable to resolve the name u.kg.
Add the following to fix that:
u = symunit;
I suspect the issue is that you are using symbolic. If you want to keep your answer symbolic, see this page (specifically, sympref('FloatingPointOutput',true);). If you want to convert it to numbers, use the double function.
  6 Kommentare
Cris LaPierre
Cris LaPierre am 1 Sep. 2020
For symbolic, see this post. For the double result, use format shortG.
[ht units] = separateUnits(ht_inpt);
format shortG
double(ht)
ans =
2011.2
If you want to include the units, you'd have to build a string.
ht_dec = sprintf('%.1f %s',double(ht),'kJ')
ht = '2011.2 kJ'
Andrew
Andrew am 1 Sep. 2020
TY4I :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by