why it can't be used as a number?

1 view (last 30 days)
i get the two numbers,but why it can't be used as the number?
codes are as this
clc;
clear all;
close all;
a_0k =...
...
(7*(pi*(299236895695882349354211250143292074432794837696010998019264235111105025867086285857225716703393375994943474388314710145530425279231694094936751573753838559683668308804586705717318577532405572751310926019978850602402986933388829967872189041967505079334457527134776725695920913029490820894091618190737582007018981123248881609405766832810885906571844560841642554557745875195596133837416187806278041346188718446378427415652931664632218552520693963927904111423023796562589807458222169180813251899478941612165421516551630292640370288119029208551271655328195803212862097952711010164277577913956666665677659619579631318908407440269042850378720433173678284194762526888543424022117471213207337770403406038677253457621013092243259978103830312242666730504916566016 - 20750269331011200360116415036212312910352135877299028493439939194823366519772502011379022357565861839905390326997665713287795440038325727999181659721450494465869215873761933751558970339504384148098414882913103224805305048707188739744198364147052460772221718220299076902687141788633437786180208383013768196424635590754826172324981902910920799462077374660843146836596972653325084435119575622200691567709412075678382412948678431271187792741312081296791924399201790440950807759820331897971382112835708328173528316703819478017584900720532692581248766385675837432061199486448683959850042687922511706116082593870247223276461458614987820509134529338589641348237053729953858292790555654734657813173652467432612073671995742135201167398951854986997306992971743232*i) - 828936621421955091548151963880843307847291795535375416000455484368447786200681453242706772228158988769816759185118325603070954760688149832256537287883555547277458963997061674296469806163315844597467876337722499266397521514236928003262420612730090951633799613261402608505687268746579762052984751883840833722997265452782325740634679946228369065062794513094226721555367991492039932355301271226642843549890226657243496492812951489274795070680772332536632002028706721327963465336618817059506810617812905747528426544229378451394680030579333940990734786237105386195148330620276786811947016143334386168521285398924768070405993332772195761700594274459658077162283131191610072701876214619494458956414354499021701960493827826796821352328964876977041282825610854400 + 1747304073542160924135488306310192055940479399206831758708530867671336590124166276308332158804763237303929110157748947231126228412647759881302739939869552348042365288388889131484818634116419402478027822070018803964714399581322285706165763172287612218207664344358484141435114761327400527750200180354617229435170985692283627692045354012374428020526820824583228053938772351992987226431087551007096652388818165018340990363015502885203150659680067152213625065379905552061984824675045406818646632695839959449362719979577614997675749426484720765363438957571335249318382856977135003335531266529392357050645924783594724245614487670268050898603965482366090558388892984991270549509142945238067086536334119244174306016456879237127201897029797582597609220055918182400*i))/(5053682337168941770164803270301725805825475936254770329535185111044921736561929088408851312367002960150756820370407208123468339090687125953491782633070235920564570527111596530127340644177793246850225678212108435883226948499742251391385600*(pi*(1096419270068734303375495273352889386039407712793348074972072840015603152964417010818110033347313805634908378476133813956765243411322625248337933930408748684286447150463397507875677407746737459433061685832049936076595644806958228997835844525187039807579503858900200499524163985590801114921114863424612092974178786537591718548093910515095857691660810675916731283320406589022019125109038379098096174864387803388799922723324554949561280012235741727774105938726844254874444711143067390964120261352558189515737056498256993 - 141578006544081209352705357744469176431506036113157493322931132415928699496570569684773433850101724780290368599361017594926295082684170506397500086461701924581252241088385194059863918725249694968170190808784878176494875810760539177266135265992893881547344662029086481335685215186011190517520783936398890280526099549432698255978732923246122763686789075589137341036776150333908042470262836909280085673806322195975188658044092591849227446604480231819319981690062160829858590481653950030452569719810284693983767943314488*i) + 6602325792647294869215525102432749990457625996212581885560509660739877041167656782797744709729605709401661147068385933861376607961159119268956713907212838176602636499382048792214346016654212233013817657291663001124264501239185792928753421837994544487917435895987670879465642142625833139856796778534426452666265568733619511323956316885710294444605723163280242746545989938168213571030047652201881233194691117754107313671833718332713338958308402627300065461605588237763661758564673317606518509575346163635346601305702400 - 7588703030659220207190006579597016121146876406591426909213650544259201154208195080346433201633110011466270117059273044768206737968768229592028140707157428374824804828416923799140807228820377649065338249055435994382100995716877992284809041466243313116136140406580850465201709835205890098680864833676850973095290156306783813691170880117171022009987893405996093916513687069783007767005928577205757690008987305034432075533071368304313180459699075241887995854299631835249443046585672216815022097701115842041085430228582400*i))
a_1k =...
...
(64387035711372752329169546652700418207030773508884671061601194082264630095221406664408154335103535628138030415021647668202928576920850087779864273039940526959063465581107268357737603081376755691235802483393666126222437980618493480676350850209572937786440813481954964597684941743712797468926726775370606104886244029686355757048516966560940142930601628084283714216609259138975758494682003703107541919726418700158688607227823441852630576395708997516133230828367572523340633837564673524340034717725988417318794184540354516299840359497728 - 7095140268966056503079122674370101634699233756035934993808273071471238536119856879277292499127930092343977300996821746787380063673699482708335618930509192535643571771369266310609682737172105236461563007925660598839994288879001970002293340604396402253002462006897400996545046263927828033585409111252003152487876125713480665678115540745439224522661090693240983945851724608205751825671443006656066255577073299864920203034500534864527459861785455393654634261606090754248585123567954670861524180667337398155785067008499781491893049753600*i)/(pi*(27839740573197233275802839377136958390003019312158243090267938187790934949589051947842949125763188374406327678890903933410470469482313869857992866397907028137485493986783633389444034040996288837834762166893615471790221680567269859712544919651675533550066305431199620669626357668490658829487107682006281127720512128012262637466558288559123081000138269973720632398952290078215743404356067933213491213465751781534268596373479711818660066223488401664866200420688445838228573277834877886256728775302879105439520478694071958427028356697041 + 24733196945265750106302507593830804007043882582113056966554417837206278434991128367347764045114412308286391057473128129203700032101488955693260716674959873253095260104077312938983230642717135013774256893353153578757610574055137715867956532550526538214052979925409849304005884256976945482446284992756192442318977355428954847302876813721241528964296514215319162295566628469648871874042494493559006423785416194413078256036099972109912998178900331978120453155274471131105022288331841744338370218103750729336007502254804817463646015997780*i) + 338830166529424266809760231595618864146273851461743111815103246707144767728489765578609289691755705522242185304984367665813470133564896922171735097417522963705925788776268964298108750664154885299828565911758068362563240468609718959792744866536152733794739771047588654471965743938123917112742739200182400792287483421410497233669458386878220739464115684300327770823898178535455853703278828978160977514932000377091132585982649035354710306085027712189594376763109989404381080126292943630022019729134635729060022483974665569033385725132800)
pi=sym('pi');
a_0k
a_1k
results are as this
a_0k =
NaN + NaNi
a_1k =
NaN + NaNi
a_0k =
NaN + NaNi
a_1k =
NaN + NaNi
>>

Accepted Answer

John D'Errico
John D'Errico on 10 May 2019
Edited: John D'Errico on 10 May 2019
It can be used as a number, IF you understand what you are doing. MATLAB works in DOUBLE PRECISION.
A double precision number will represent ANY integer up to 2^53-1 exactly, because it uses a 52 binary bits, with an exponent, and a sign bit to store the number. All of that fits into an 8 byte numeric storage form. (A standard provided by the IEEE,) Beyond that point, a number will not be represented exactly, but a double can still represent a number that is as large as
realmax
ans =
1.7977e+308
So if we try to create a larger number than realmax, it overflows into an inf.
realmax*2
ans =
Inf
Now, what are you doing? You are adding and subtracting numbers that are all overflowing into infs. An inf is a number that is just too large to store in a double. But we can have +inf and -inf. The sign bit still applies to an inf.
Then what is inf+inf? This one is easy. If both numbers in an addition are +inf, then the sum is also too large to store in a double. It will also overflow. We just don't know how large it is. So inf+inf must result in another inf, and we don't know just how large it is.
But how about inf-inf? This is indeterminate. It might be zero. It might be still a huge number. It might be anything, from -inf to +inf.
For example, we might have tried to compute any of these effective operations. I'll add the answer afterwards.
1e1000 - 1e1000 % (In theory 0)
(1e1000 + 1) - 1e1000 % (In theory, 1)
1e2000 - 1e1000 % (In theory, still effectively 1e2000, so +inf)
1e1000 - 1e2000 % (In theory, still effectively -1e2000, so -inf)
1e1001 - 1e1000 % (In theory, 9e1000, so +inf)
Essentially, all of those operations are possible, if we could carry infinite precision in a number. But we can't. Once you store a huge number as a double, it overflows into an inf, or a -inf. The information about that number is lost, and all you have is an inf, or a -inf.
But we still did not answer what the difference of two infs is, and this is because it could be anything. Therefore, MATLAB gives you:
inf - inf
ans =
NaN
Yes. it cannot know how large is the number. So there is one "number" that carries even less information about the result than in inf. That is a NaN. And that is what you got each time, BECAUSE you subtracted infs. You can get NaN in other ways. When a result is indeterminate, the result will be a NaN. A few obvious ones are:
inf - inf
ans =
NaN
inf/inf
ans =
NaN
0/0
ans =
NaN
sin(inf)
ans =
NaN
Now, CAN you do similar things in MATLAB, without converting them to infs and nans? Use the symbolic toolbox, and the function str2sym.
a_0k = str2sym('(7*(pi*(299236895695882349354211250143292074432794837696010998019264235111105025867086285857225716703393375994943474388314710145530425279231694094936751573753838559683668308804586705717318577532405572751310926019978850602402986933388829967872189041967505079334457527134776725695920913029490820894091618190737582007018981123248881609405766832810885906571844560841642554557745875195596133837416187806278041346188718446378427415652931664632218552520693963927904111423023796562589807458222169180813251899478941612165421516551630292640370288119029208551271655328195803212862097952711010164277577913956666665677659619579631318908407440269042850378720433173678284194762526888543424022117471213207337770403406038677253457621013092243259978103830312242666730504916566016 - 20750269331011200360116415036212312910352135877299028493439939194823366519772502011379022357565861839905390326997665713287795440038325727999181659721450494465869215873761933751558970339504384148098414882913103224805305048707188739744198364147052460772221718220299076902687141788633437786180208383013768196424635590754826172324981902910920799462077374660843146836596972653325084435119575622200691567709412075678382412948678431271187792741312081296791924399201790440950807759820331897971382112835708328173528316703819478017584900720532692581248766385675837432061199486448683959850042687922511706116082593870247223276461458614987820509134529338589641348237053729953858292790555654734657813173652467432612073671995742135201167398951854986997306992971743232*i) - 828936621421955091548151963880843307847291795535375416000455484368447786200681453242706772228158988769816759185118325603070954760688149832256537287883555547277458963997061674296469806163315844597467876337722499266397521514236928003262420612730090951633799613261402608505687268746579762052984751883840833722997265452782325740634679946228369065062794513094226721555367991492039932355301271226642843549890226657243496492812951489274795070680772332536632002028706721327963465336618817059506810617812905747528426544229378451394680030579333940990734786237105386195148330620276786811947016143334386168521285398924768070405993332772195761700594274459658077162283131191610072701876214619494458956414354499021701960493827826796821352328964876977041282825610854400 + 1747304073542160924135488306310192055940479399206831758708530867671336590124166276308332158804763237303929110157748947231126228412647759881302739939869552348042365288388889131484818634116419402478027822070018803964714399581322285706165763172287612218207664344358484141435114761327400527750200180354617229435170985692283627692045354012374428020526820824583228053938772351992987226431087551007096652388818165018340990363015502885203150659680067152213625065379905552061984824675045406818646632695839959449362719979577614997675749426484720765363438957571335249318382856977135003335531266529392357050645924783594724245614487670268050898603965482366090558388892984991270549509142945238067086536334119244174306016456879237127201897029797582597609220055918182400*i))/(5053682337168941770164803270301725805825475936254770329535185111044921736561929088408851312367002960150756820370407208123468339090687125953491782633070235920564570527111596530127340644177793246850225678212108435883226948499742251391385600*(pi*(1096419270068734303375495273352889386039407712793348074972072840015603152964417010818110033347313805634908378476133813956765243411322625248337933930408748684286447150463397507875677407746737459433061685832049936076595644806958228997835844525187039807579503858900200499524163985590801114921114863424612092974178786537591718548093910515095857691660810675916731283320406589022019125109038379098096174864387803388799922723324554949561280012235741727774105938726844254874444711143067390964120261352558189515737056498256993 - 141578006544081209352705357744469176431506036113157493322931132415928699496570569684773433850101724780290368599361017594926295082684170506397500086461701924581252241088385194059863918725249694968170190808784878176494875810760539177266135265992893881547344662029086481335685215186011190517520783936398890280526099549432698255978732923246122763686789075589137341036776150333908042470262836909280085673806322195975188658044092591849227446604480231819319981690062160829858590481653950030452569719810284693983767943314488*i) + 6602325792647294869215525102432749990457625996212581885560509660739877041167656782797744709729605709401661147068385933861376607961159119268956713907212838176602636499382048792214346016654212233013817657291663001124264501239185792928753421837994544487917435895987670879465642142625833139856796778534426452666265568733619511323956316885710294444605723163280242746545989938168213571030047652201881233194691117754107313671833718332713338958308402627300065461605588237763661758564673317606518509575346163635346601305702400 - 7588703030659220207190006579597016121146876406591426909213650544259201154208195080346433201633110011466270117059273044768206737968768229592028140707157428374824804828416923799140807228820377649065338249055435994382100995716877992284809041466243313116136140406580850465201709835205890098680864833676850973095290156306783813691170880117171022009987893405996093916513687069783007767005928577205757690008987305034432075533071368304313180459699075241887995854299631835249443046585672216815022097701115842041085430228582400*i))';
But, remember, the result is a HUGE floating point complex number, since you are multiplying integers by pi. So that result has a huge number of significant digits. The symbolic computation stores them all.
If what you really wanted to see is the number then converted back into something small again? You could use vpa, and leave the result in a floating point symbolic form, here with 20 digits.
vpa(a_0k,20)
ans =
- 0.1037668731385217731 + 0.14893619441956292146i
Or you could make them into a double directly, which is fine as long as the number did not overflow (or underflow) a double.
double(a_0k)
ans =
-0.103766873138522 + 0.148936194419563i
But if you have no idea what you are doing, and do not understand how numbers are stored, then you just get NaN. That would be your choice.

More Answers (0)

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!