Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How do I increase the precision of MATLAB?

Subject: How do I increase the precision of MATLAB?

From: Thiago

Date: 10 Jan, 2009 22:33:02

Message: 1 of 16

Folks,

Simple question. How do I increase the precision of MATLAB, if that is possible by any means? I'm trying to calculate this:

----------------------------------------------------------------------------------------------
>> z

z =

     2.225167162095353e+003 -9.020383145678592e+002i

>> exp( i*z )

ans =

               Inf + Infi
----------------------------------------------------------------------------------------------

Yes, I know that exponentials grow fast, but I'd like to find an exact number.

Thanks

Subject: How do I increase the precision of MATLAB?

From: Matt Fig

Date: 10 Jan, 2009 23:41:02

Message: 2 of 16

It seems to me you could define:

t = i*z

t =

     9.020383145678592e+002 +2.225167162095353e+003i

Then use

e^z = e^(a+bi) = e^a [cos(b) + i*sin(b)] = (e^(a/2)) * (e^(a/2))*[cos(b) + i*sin(b)]

Now we can get numbers for each term using Matlab and go from there manually adding exponents. Someone else probably knows a scaling trick that is much better.

Subject: How do I increase the precision of MATLAB?

From: Matt Fig

Date: 10 Jan, 2009 23:43:01

Message: 3 of 16

Oops, obviously I meant:

e^t = e^(a+bi) = ...

Subject: How do I increase the precision of MATLAB?

From: Roger Stafford

Date: 11 Jan, 2009 00:43:02

Message: 4 of 16

"Thiago " <thiago@mathworks.com> wrote in message <gkb7mu$4r$1@fred.mathworks.com>...
> ......
> z = 2.225167162095353e+003 -9.020383145678592e+002i
> >> exp( i*z )
> ans = Inf + Infi
> .......

  What you have asked for is impossible with the IEEE 754 binary double precision floating point (double) numbers that matlab uses. However, it is possible to represent the value of 'exp' for large arguments in terms of an integer power of ten and mantissa separately. For this purpose I will just use a real example.

  Suppose we want to find exp(7.0873e002). This will be a large number indeed but still just barely within matlab's capability of direct calculation. However, we can find the separate exponent and mantissa without calling on 'exp' as follows;

 a = 7.0873e2;
 x = a/log(10);
 D = floor(x); % D will be an integer
 F = 10^(x-D); % F will lie in 1 <= F < 10

Then D will be the power of ten and F the mantissa

 F = 6.27376373225551 % The mantissa
 D = 307 % The exponent (power of ten)

Compare that with the direct answer:

 exp(a) = 6.273763732256170e+307

  The same trick works for larger numbers which can't be evaluated directly.

  Your problem with complex numbers is a little more complicated but the same principle applies. One difficulty you will have is that the sine and cosine of very large numbers like 2.225167162095353e+003 which you will encounter begins to lose accuracy because that represents over three hundreds periods. You will lose perhaps six or so decimal digits of accuracy out of sixteen in the process.

  Another possibility for you is using the Symbolic Toolbox for which you can set whatever accuracy you desire, though at the cost of computational speed.

Roger Stafford

Subject: How do I increase the precision of MATLAB?

From: carlos lopez

Date: 11 Jan, 2009 00:43:02

Message: 5 of 16

Hello Thiago:
You are not looking for higher precision: you need more integers in the exponent!
Yours is a huge number; exp(709) is the largest that fit into the IEEE double precision format. You are requiring nearly the triple of the exponent, implying nearly the cube of the largest representable number. Maybe you want to manipulate your exponent some way to produce something interpretable...
Anyhow, try the MPTOOLBOX by Ben Barrowes, available in the FEX. I am not shure if it could provide a solution, but...
Regards
Carlos

"Thiago " <thiago@mathworks.com> wrote in message <gkb7mu$4r$1@fred.mathworks.com>...
> Folks,
>
> Simple question. How do I increase the precision of MATLAB, if that is possible by any means? I'm trying to calculate this:
>
> ----------------------------------------------------------------------------------------------
> >> z
>
> z =
>
> 2.225167162095353e+003 -9.020383145678592e+002i
>
> >> exp( i*z )
>
> ans =
>
> Inf + Infi
> ----------------------------------------------------------------------------------------------
>
> Yes, I know that exponentials grow fast, but I'd like to find an exact number.
>
> Thanks

Subject: How do I increase the precision of MATLAB?

From: Walter Roberson

Date: 11 Jan, 2009 00:58:37

Message: 6 of 16

Thiago wrote:

> Simple question. How do I increase the precision of MATLAB, if that is possible by any means?

There is an indefinite precision toolkit available in the matlab file exchange.
Or if you have the symbolic toolbox you could use that.

> z =
> 2.225167162095353e+003 -9.020383145678592e+002i
>>> exp( i*z )

> Yes, I know that exponentials grow fast, but I'd like to find an exact number.

That's impossible to do. e is a transcendental number -- one that is infinitely
long. e^x is certain to be infinitely long if x is finite and non-zero,
and conversely log(y) cannot be finitely long for any finitely long y
(other than 1).

Below is your answer to 10000 decimal places. The \ (backslash) indicate
continuation of the number. Watch out, the leading decimal place is 0
instead of the more common practice of writing the leading decimal place as
non-zero:

0.3410791142560920539159367203658095165749276531859709627022991675282608487\
    35634973256716650334192541528091913666079726209733590318276945111127381\
    05645705279925537111550909165350165053732654129289626520114501837751859\
    55833377248648143420642164277937392380708784121155987107877182505226111\
    93067860827282888701598925971779568841101916188660727847234970548619238\
    28655225524223203075715279873971506008005760164864049657263089835824563\
    84748364154618496705984031798198832254926411679488020281367145019655017\
    70825333996894621928222396757838091368411047178059929679708796978035873\
    62204135160544651189377254764775362735403248914527733262875748585797963\
    45186024143573243111491745148872808264303300507577139921049097582614284\
    37118097881365750215382558672602898782210135002334610315448401772244478\
    92106656466959806604563607119113609991030984042843096812974847917931106\
    00270661774930173394899049492529922869872356673494909689611612535097109\
    30572731025448050288687719118266586051799304891284920175701311934984383\
    91449917219398058054267885802629852641336166902603089973666915781095994\
    38168662208705192440173569143174227553645373854611608355171834580114158\
    14466958199188329709761693090729300787317331064912128425721563187054171\
    24733469105002635008938170343802420809406288794065623946189831442083491\
    77239925689634845338106847941194788093898100300328151110657172576642725\
    35460565909019084592185878051047349579608596387328593864854783304792407\
    10750779787652300683804858609632830149269373602600119102388789116221911\
    31645408489295940879369473000060357815198179026869381248971292035983330\
    53834826009153399342709197379394804298464716436407184126074252024348144\
    93046326028616352505235493713489944103634409331933619888310688835275742\
    46681203282333914025296494923195861254522724292685488610269741432846748\
    44855735096179156830948953418781001962060616206901861150119031311001994\
    55709590298878984663482094818962462828877424010003831648365251644165738\
    07216705690445429186901041983200578916184223996284380020323769929007335\
    40001694934496922914176637142821864949759568321688260222234559299802167\
    69075724060171045627483835384836337825676824031014130768833358943596751\
    74614556538681458275948316445847962848936463356117470044989354355532118\
    09234989932910341533272006483613235608093513144651877675386379783219298\
    29587902351394766784413174974069054955403025348037677391365625587836634\
    26296685222145252237485521282799099842318162650157290536146288930792830\
    09295294272570391668352931148807516716859103982899917014034281082350091\
    44523525872537911740641254865930551647817075769134257602519921076705588\
    43974567414873602759912454339027739831622266671007745027642027750714722\
    01587475145011166016915401163175356347846946075694700199781468189966522\
    68839732371289113248478888921757363181126465467245911138154363070117583\
    55606624987594172171674403933337333236357818098634452400300619358399268\
    01254991508584490946687080395972425417899217672767886509685302496430159\
    32633527353919800883887533358556859570577155236587482485219088575834729\
    61099216107148151753697837568075671839227592024058123712586477570288523\
    79080035701622228057315477542801170608923279917516802434142826049277190\
    17296858389688726531719768433863076023762768864072282317192955665535770\
    27053482458826410396139064009817549189732338705566147293502773997528149\
    70525272072105565311894886502739152231015395236482040654831101202125274\
    65692544073402145105655393375604994967936092670507989566784419200633968\
    14478781631679662981872523723085560457524972062234091820117247243731035\
    14483999129278777654503630365672376304377168355189988460901514130384094\
    62546608136491423947069931616501767671046677771383897981682599561959784\
    87284269702052738935403499233022725625726949955857678644661026522957333\
    91887085447852091440914767030285109463082996273620910099960933422600123\
    58154563113303122470168747218231869079495145512059974776212157466794006\
    93671787276784171185938628765695651531576009820901524774151200142318716\
    64034838625985576874951012763316136595340370595537464511700408639963819\
    64105157861663059537164816842069925195899960235217940600102162099853299\
    56819763614234390231760268422404228368254897312383314064535955487551598\
    36519495953935048546251741840590005645962213811384540180648685233404321\
    27026279021156463200279381732280739448369788477552621534203681385172768\
    91083769618071744952860891384952665375940496068558715723983449705096266\
    63353930613457413518167646484564746878413638018130929815472526092227851\
    44315224119458216980021683446843840325062722781551453341260359650546646\
    75621076411054317611176091733948942088466701916528045194767415911977361\
    23168956220048777532533978075797105189930925620507433486898476899531811\
    12128388569959663423190466732746164898128271509289076296619004952302805\
    36411456016840092454851974553461288650124502603741391964102272598219618\
    63668641510622720488850987569182066629363037359354238511072455507355700\
    97016784133777591637032098452702762755451904540959339766246368184653268\
    21607516355201141889887842973921274566586759442321539570252314081171407\
    17478383593989280098742601389589176240031231667893286205869342891475494\
    23547341110429326650637667638877874304774765066017615858714591279410843\
    04036316087364726420610234516595202395703449484829975688464489592847418\
    45515897485071577825606973998980280824932500084451746743473871847178239\
    30892537266585857464117062811463695629971133366708747891969633141800332\
    19600967349841618382825515201656496542011335498965888590465832452830987\
    90713634377282168535536728025620562108201778200674658143579850255222439\
    92932879873976058522253101123365392291660024648143099184070364973909453\
    23227934755998999562163685462984105542118708881876358118413207906492176\
    97914718625650227316643349591293805164297247931334833598486366194914429\
    10318547212641325308761258202039273688704676956794153599327485782858562\
    80875838518082965893288898678957039652530761872170241458064404071996470\
    83208685225908608997695367105955926027460457865111880624311306847720807\
    43220124957251542317852319980863188558565976658392077180833004294078801\
    28444147900751629969806894547561348132970059672535594220418101331991446\
    18272947080556747309261323570869128229926464856342786399476289652976819\
    33090664540228807968128448197429793188555969245128912007708983419112379\
    19548910063869441231567002948520183348776917264164683334757509630022524\
    76721731484100748793187656021479355440859523991681851731389909677270831\
    60986834397651939311034856035427936255433557399346059748736447282564313\
    39291855039471236400329936027966508667728538463420373699931234043485122\
    41399180204847744857712561217008089375689081884951228172590790429963322\
    37865303133761768879913775983869967704692998803151739358801964712778659\
    78222761830975654433889855828008233959514847281177609413731761464028198\
    80844758741757429285742420545761529305175365250116581264676527571443869\
    47468312751671083235268984871685451902746160208522062481556571721039733\
    26259422288689953282999240662471196813867739449001852434107377196453408\
    86243900504545841130389612532929550137040958394276100336945188517557502\
    17978399272737759152309546189309638785937545428591524061511155097135597\
    66476873003698881883027178425429645894874529265805264823409712069488580\
    95465348974614934020993347712734514433431982897800353731616098997196954\
    85613496074261109537448475972423766150042816740473951400848902471334909\
    08656753886126642724938357964571957105119095291253677140163263098007501\
    58634621231851972668651421304549805051790068957287590254676607258373158\
    75366437794562877151975812012228597328150078795507035383516062780687038\
    86051443439670424322066524161814719136431929769567748492829046885192680\
    01118891844923567027311102214711499711875077025239490526126003309161618\
    09449049318633194237120894243592015208482326242378618064881201439011518\
    36995051356382990144118375529259714162873986586844083078517748998973304\
    31311606583776889974906716005167972915319208869206357823236254391044578\
    96658467347352020561270564862910019737996448382524110297947994172912198\
    31941393296263441885769931894882102281607620349848169388782121488089552\
    24876344932717070239995206563742153695722336155727347585638750886275523\
    44067903394901558996899263079957880175584503308751331750291469157194119\
    56170567086622139043616877562947791414102610166506566483514710771747090\
    59046712323749051423429015080144874701806479507058487460774403976399820\
    41126624901002859295021991786745663000509196215971733268033726494846179\
    09703265638357373945527695246255017007334384364641179420297820997574786\
    23044478779488950692259903467238456761237553414514020755022110571499350\
    92586670386804755519841510267141639668788714601052811419407614654766541\
    26244352267577717274042432794063267025870697897140012539118851979815421\
    86387305119629511185441939674325375572576704491629688746900535050527254\
    09615736330481373468639512388905713562827636059190467686076309505131173\
    74112655701263826417336266009161808126735202572384898304078576132587971\
    51918745036447307428430265416894273845302980273401223619739030765208768\
    68264641671064050354823708123946130829537248281599376619589688609229386\
    89913865666550116230105499440777867075389527974286789476073471952859379\
    07632319424369857822360687778568623323081591964917035434217478174858507\
    25538598337541676562497314933618378065472950946953980030797651633638762\
    16753390822207736855983465900528076292947288778072542476369618628862581\
    75479796281719381764973766172617617991598739917423099534831538211490030\
    36839714474023370085261105612788130417833359476605882109371857809263484\
    55867285404701429252446697433646998003407999880332566458655365291077089\
    45946596709262935892587497533825076626265569811968054366220394530430253\
    29762376031866073562598999150915480474629766120290688926930078414573115\
    92528102499433394101884272526766123223331900729604634979662326743572715\
    12760746897720173880992979942904717846194744849767740738293763574101855\
    48884007803606773262789145856715883348082693916349884320204005635471542\
    92637185622990732065483858963713308359297875439819991845486925726725979\
    84696305557470095965823603581049591717287531884651399108374404836717401\
    5638826434896866642626394548681637463952828157049934969851*10^392 +

    0.44\
    75212655676737435045552766009719480471798083766177736277453836166132138\
    99518512529997961452905882467144781429885788514373549631198447607333475\
    43766375833980488697438044868964130765963807328022944103762872499671371\
    14200053270351632657211521730111673733966459538275534907746943150266030\
    81712894628359730461412030082267908903300009341529099670623167372822767\
    14286112810770766140076390662667918973459306804162233605890117680091005\
    07216131427520762586920652768744083344791049108223861490550319894456987\
    29609298152972434975532352088392683982024791875819165369112945339860083\
    17555194763462828678101103415110266588143673456942533438764230695334028\
    50569701737527840988442418402740372505234315477409145727857969840621064\
    55649098067726199912776433101575134158051874959090548581067795706111035\
    68752007697022037304352831367349450817804314029574815214280197780474393\
    21638823394285681367476434338403987433549326729680975314840421144739446\
    92068897318159177434467770665047714180865538543251387735636566967095149\
    61907252324701262797006056258334641856342350361352042807078546352703378\
    50439663954640515382320716941163821968135608526944846754303481627005651\
    60364487238313246148394445741545415303281999311251426932732846001829393\
    44383193016626984867145613819511833475057447661242126964327977764217077\
    93993588315210452489756929955285605451804306905888056648717180513862078\
    19674477305063704303010326862312518150783470015607671874099360426636587\
    16722434518938727388055347011156136264003288224242911318262582837508078\
    48033181933853750566991700210620004165062404639735307963644128419963771\
    45596920617647752296651972613788921298367013571607920531970368248520576\
    49609196264678848695057653005071600563892495872885103835750545219418408\
    75002542470746331449401978765100481057086352041718385921048209474118998\
    63116295005253410214524280983493178521386800319522631660604628909993398\
    80461103939412270912431670163720961832582390082306031471531790095793817\
    82528158303707584565425077422471802559958167315282283456078599935005709\
    52018174539862592247918577961419485689762107299414964809751525985944662\
    69977241250411701439676069003126171779881832963360424477666349101399695\
    41382500444049938372981216617936103613093436596157593906863061600627963\
    10154937217642636573164216637619207975402926180256300905411423148984254\
    09946666998714142831292313932329068987583153887978535136032911684294103\
    65968774710815013155711450554017817731097256622900141942168628000061125\
    48165441542405666216921851597592390085511124379309389272920950685782760\
    85048760979278722342244727662928118220215636663835653874233007366458533\
    44141774012415931206706963019366942404370250557270737540837194024929557\
    23853254839079957279483811777372153981276150658553701018813735496670045\
    03822109115252094831516866677041772974105401306607062222092659884360388\
    78942310706651372968138597837370651206885617528207353604557476637910797\
    84477778234899969279637333430347034507866990667890270855195333693755146\
    15417800628018455800013642155590868143533038616413360349726480598943403\
    12441533410816816255801562901935335729653418995733717660423693698118074\
    12776423050468237000049964008646000678998635445371558733362999184967151\
    42454988417487010452824336744791548067832267067339930661070969943920937\
    52441468163047689047965422831810755344773153348396147292364405182569160\
    76134900792198640201501166754364329383521909473793976286237243421099699\
    15469057024173612313903645946184871091969919029907448869515450301792387\
    25545871840417851465048110812042348838163871456601821244032569831737984\
    72287430303796449072292389341029292715744675288606779191532171913521398\
    92417168681922878297723344810976119295824995891958508805662284466395913\
    09190870289599142323890296259491893130001284698984227161526648043533761\
    50767757201259973127673196829960766411406541797919477786098592036567364\
    57457563797310713245487458420916177961400290876234131890878222548882800\
    24101654403156429551981048066760895623393513262544946869353038182112541\
    90932637152520091189421500444332490109745688973860057672702599381748621\
    26389209091403682509668065894067893663141480172101397632070950994110341\
    91138100820583208393031844898420953253125547267233405803705028011436011\
    27835095902332861900833320897532945778034164083126970095039782574203948\
    86809871337701788150311616727417455295463744174711797396317631005039259\
    07308783643666131577652797957170858932017844579865239396408289012546464\
    58089986144998152825326492578634907239727723676629987366527529661214328\
    47523129598431783248575676142734583802586217682939503302011144158713346\
    24264099158670828764700683566109164230333651931766016423408296410931507\
    37984759730747620820591318992817577545222494785246080278702156796961800\
    97136146957309945357874413588750332427544768078767653160731393029883780\
    71606047759627327859608780962230989668177672958616705712900109356549004\
    20199088704179963301328424150797824115908838144548180604160742196920348\
    73774253111282618831700001821192057060822777559326199241210435691444052\
    82881709208833212362673110749492821417102706536638246324544390919342354\
    19986967962642010906905377311610602458070267007924167985008045214760805\
    74599620805689613140010786305802432240021334169987196841411810169293974\
    21136010882198999824803921528631432843177764071404624474807646051464145\
    94269163284857227654642220654129598001377092199147463009870965256938232\
    41044965661302462634097677857818643817652113128388412782449261667027306\
    84126477255985987902482450267855509274669252988522462693016809675715022\
    61872112648298127608594092953237155265066298062053939602282299269428309\
    20564661878826738217590195282810154214778029069864511038499014939175228\
    53579288839322326753568459067322452184747640867096781712629957065003271\
    41701941844442345148148944387927932879115018129376487920229836882638601\
    57388433926416656240480089849029392033355647118820769435087743286083770\
    39504761739763461387062912641040390010723232526152097814228827501256475\
    59712528565223229069890379550546111810233075563218346882965237961697358\
    43131446226547799704342595227981590769198628947240341222964151586403116\
    70648892576245753664381725709097909979554913146578497219473619203099849\
    70245494739659335593180960024520766924259093428443173213234851862913668\
    43967259242331286687143418286648047571723704353656645899453987789448080\
    32917780972777475130699014602052891393304414165095836939433721894472905\
    25904900073322816678998664619223482029734673296995911431258752443213071\
    56247632584946745777439971579099567029372160079925495110453062241282666\
    35042112530486252059606337065539505400388350712980222726080860581744545\
    55357644472072192188755750771547543008633631503157588052476494002800690\
    80680513039722483439682727519728048716949566242902401466316669028680116\
    24783982488288345277670090980584264872868177094416737595298891476191880\
    18538337594337920972989334051913135795200205082667665058401533680127472\
    88904231254108870225999452343536699166203912896495477885127966578301128\
    47432831886978574733641013829082659752896257229876705336669223625175736\
    77134464144126068444098848183108971440468792953891301598475956027769736\
    34366625952972038205085339005671388183342400181755559493783527902103244\
    05276970686453055823211439015139600216486425464599933022471944813307411\
    63710044875034315680510306757379394294399491896503566304688307573607914\
    87594840945449267771717429698392010168258064826364930983586748916342026\
    48764846003806034609444158518938174570042455903077443194661936230134929\
    99546671123782996768196343141284770024299591571005948441746275586008704\
    04277374292615759769309876248943977404114472621835430405142837156060858\
    35088699124654479955703783379054760641598618197100031704759225364323309\
    98808428417365468674037829631011353607333726350124437948663496708803066\
    27637711902196449155394157677779692673844812725713258802177841913795914\
    31632939738119788089504342145324284764298602650877665766888936446753234\
    12025043008572727337936020215325426603826062728982406888558821169145102\
    30228835316326936241121421947712213964917198660949425163546194829862612\
    42969215366860176543815558732483368496229779794612974388008729997723337\
    03053961325003773974285836494273525462073879363943061441540138625919831\
    07980363705022242208683378787253052544477654931282407925870563718039510\
    49786618313958608151925289346850577497663541663649400266513904305809112\
    71509950216030936579570697333723072347371230752494533186800912349837632\
    66621463426429053529221183893090874055338387916530601245188031567123788\
    96139081449868826718774693437659702514296752995586948701918181621161480\
    10707824537544444631765295949688677387454508383033587137891746777815919\
    00799556478723481681911919812315441915893413965188960575440742279615041\
    67658739131895898655641000029941142398834323120576499870203231310123194\
    72552706894774100776241110828669488238798224596156033791002905886039676\
    33958369854167167227448994074342285722900893913281081389173431512672860\
    47361031791025882473674510952863837643416869465393724290916251686398394\
    96447206448890784187482697371661750722382287781104128050653379759096481\
    89600517066301991685355024853575152426397915613246158803779226760075820\
    11163576158872697389829519792252869201885673065796777576733035019451691\
    71285955098826437901512086332123016151502853247823089077412606462154554\
    12802186506209522206597559172505919498430887567416733112028736955854953\
    52261469503429849226397797163880642257173534974645822324881371011267697\
    38418557878664970971250828302888912337300679465299510273729322000304937\
    69563168915539397730017678582095299204329921004354725002059454655057981\
    00006921522607577094283560847393601398375133944361743463378259284158086\
    29448546825165437608400775616725038469580369194128081580152695829926893\
    41008338773611673627280919108235371760486660093413228646191120230298865\
    20839382140242219432135284066304394170372266497281561390763915658365319\
    52401763594247681986576005764516164821395269460618062627023027759398073\
    28525476659104022791679261928308522258801892840649662427069093987830771\
    54312363737784586024039869762700942882276763868118638928232836559237023\
    39346244347912667559146765971971830213091399652391351869036058351794456\
    3190107751228318653969013047157306679028567200548852925742*10^392 * I
 
--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: How do I increase the precision of MATLAB?

From: Matt Fig

Date: 11 Jan, 2009 01:50:02

Message: 7 of 16

Walter Roberson <roberson@hushmail.com> wrote in message
> Wowsers....

The method I proposed gives:

34.107911425609309e190 + 44.752126556765489e190i

We can really see the fp issue come into play compared to Walter's (Maple?) solution.

Subject: How do I increase the precision of MATLAB?

From: Walter Roberson

Date: 11 Jan, 2009 02:15:58

Message: 8 of 16

Matt Fig wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
>> Wowsers....
>
> The method I proposed gives:
>
> 34.107911425609309e190 + 44.752126556765489e190i
>
> We can really see the fp issue come into play compared to Walter's (Maple?) solution.

It was maple, but even with 10 digits precision I get roughly 3E391 + 4E391*I
I tried with your method and get close to the same values -- same order of magnitude
anyhow, with the first 7 digits being the same.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: How do I increase the precision of MATLAB?

From: Matt Fig

Date: 11 Jan, 2009 02:22:01

Message: 9 of 16

"Matt Fig" <spamanon@yahoo.com> wrote in message
> 34.107911425609309e190 + 44.752126556765489e190i


Of course those exponents should be 390... typo #2 and counting.

Subject: How do I increase the precision of MATLAB?

From: Peter Perkins

Date: 11 Jan, 2009 18:20:19

Message: 10 of 16

Thiago wrote:

> z =
> 2.225167162095353e+003 -9.020383145678592e+002i
>>> exp( i*z )
> ans =
> Inf + Infi
> ----------------------------------------------------------------------------------------------
>
> Yes, I know that exponentials grow fast, but I'd like to find an exact number.

Thaigo, you may have a perfectly valid reason for wanting to do this, and others have suggested strategies, and perhaps it's an interesting exercise. But usually this sort of question is a sign of a naively implemented "textbook" formula that was never intended for real computations, and a sign that intermediate values are getting out of hand. It's hard for me to imagine that a number whose magnitude is something like 10^300 times the number of atoms in the observable universe (source: Wikipedia) represents anything real and could really be a quantity of interest. It seems much more likely that you are now going to turn around and divide it by a similarly large (and similarly imprecisely-computed) value. I could be wrong.

Subject: How do I increase the precision of MATLAB?

From: Thiago

Date: 11 Jan, 2009 20:40:03

Message: 11 of 16

Thanks for your feedback, folks.

Walter, I could not find the "indefinite precision toolkit" in the MATLAB file exchange; I think you meant the "Multiple Precision Toolbox for MATLAB," correct? Well, instead of downloading it, I first tried the Symbolic Math Toolbox, and it seems to work. Thanks again.

Here's a sample input/output:
------------------------------------------------------------------

>> z = sym(2.225167162095353e+003 -9.020383145678592e+002i,'r')
 
z =
 
(4893194336938328*2^(-41))-(7934412924534611*2^(-43))*i
 
 
>> w = vpa(exp(i*z),12)
 
w =
 
.341079112224e392+.447521267216e392*i

------------------------------------------------------------------

Subject: How do I increase the precision of MATLAB?

From: bubu

Date: 12 Jan, 2009 00:48:35

Message: 12 of 16

Walter Roberson a

Subject: How do I increase the precision of MATLAB?

From: Jijo Ninan

Date: 10 Apr, 2011 18:27:02

Message: 13 of 16

Matlab handles floating-point numbers in either single precsion or double precision (defaut setting) format. While double precision numbers use 64 bits, single precision numbers use 32 bits, based on IEEE Standard 754. You may convert a double precision number to a single precision number using the command single(number).

MATLAB provides mathematical expression just like most other programming languages. These expressions are variables, numbers, operators (+, -, *, /, etc.), and functions. To 'accommodate' EE folks either i or j can be used to describe the imaginary number (square root of minus one). There are standard (built-in) functions in MATLAB like sin, cos, inv, exp, sqrt, etc. Users may also write user-defined functions to perform calculation like a subroutine function in C or FORTRAN.

You may control the displayed string by using the commands

format type

format ('type')

Available options for type are:

short e (scientific notation, five-digit floating point)
long e (5 digit for single precision and 15 for double precision)
short g (five digits)
long g (7 digits for single precision and 15 for double precision)
format bank (two digit decimal)
format rat (rational)
format hex (hexadecimal)
format loose (line feed added)
format compact (line feed suppressed).

Refer to Matlab's help file (help format) for more info. Unfortunately, Matlab's number display control is not set up in the same way as in most calculators, e.g. fixing the display digits trailing the decimal. However, the user may display a number with two digits trailing the decimal by using bank format. The following examples demonstrate how Matlab format command displays numbers.

Examples:

>> w=pi/2

w =

1.5708

short g (5-digit number) is Matlab's default format.

>> format long g
>> w

w =

1.5707963267949

15-digit display indicates double-precision setting (default)

To display single-precision result, use the command single(variable) as illustrated below:

>> single(w)

ans =

1.570796

Note that ω is now truncated to a 7-digit number.

To display ω in scientific long format, use

>> format long e

Matlab display:

w =

1.570796326794897e+000

Short scientific format can be specified with

>> format short e

Matlab's answer:

w =

1.5708e+000

To check with Matlab if the results are the same for long g of 2*w and double(2*w), we could ask Matlab with the following command:

>> double(pi)==2*w

Matlab's answer:

ans =

1

which confirms that the two quantities indeed are the same! (1 for yes and 0 for no).

Equivalently, you may ask the question in a different way:

>> double(pi)~=2*w

ans =

0

It means "no, the two are not unequal!".

Bank format reduces or truncates the number to 2 digit after the decimal (dollars and cents).

>> format bank
>> w

Matlab's answer:

w =

1.57

 

Subject: How do I increase the precision of MATLAB?

From: Roger Stafford

Date: 10 Apr, 2011 20:57:05

Message: 14 of 16

"Jijo Ninan" <nnjijo@gmail.com> wrote in message <insspm$67a$1@fred.mathworks.com>...
> .......
> >> w=pi/2
> ........
> To check with Matlab if the results are the same for long g of 2*w and double(2*w), we could ask Matlab with the following command:
>
> >> double(pi)==2*w
> Matlab's answer:
> ans =
> 1
> .........
- - - - - - - - - - -
  Jijo, you should be cautious about giving such examples as:

>> w=pi/2
>> double(pi)==2*w
Matlab's answer:
ans = 1

That case gave exact equality because the number you divided by, and then multiplied by, was a power of two. Other numbers will often not produce equality from this kind of operation. For example pi and (pi/25)*25 are not equal on my computer.

  You should be careful to make a distinction between the way a number is displayed and the number as stored internally. Two numbers can easily give rise to the same display, even with the format long, and still be unequal in their internal values. What counts for computation purposes are the internal values.

Roger Stafford

Subject: How do I increase the precision of MATLAB?

From: Pavel Holoborodko

Date: 10 May, 2012 01:21:23

Message: 15 of 16

You can also try Multiprecision Computing Toolbox for MATLAB: http://www.advanpix.com/

For example, your computations done with 50 decimal digits accuracy:

>> mp.Digits(50);
>> z = mp('2.225167162095353e+003-9.020383145678592e+002i');
>> exp(i*z)
3.4107911425609205391593672036580951657492765318597e+391
+ 4.4752126556767374350455527660097194804717980837662e+391i

mp.Digits() setup precision for computations in decimal digits (you can use any reasonably large number).

z = mp('..') converts 'double' number to multiprecision type. It would be much better to compute it using arbitrary precision arithmetic from the start. Otherwise final result will have only 15 correct digits anyway.

exp(i*z) is computed with 50 digits arithmetic. Matlab calls functions from toolbox for arguments of multiprecision type automatically.

"Thiago" wrote in message <gkb7mu$4r$1@fred.mathworks.com>...
> Folks,
>
> Simple question. How do I increase the precision of MATLAB, if that is possible by any means? I'm trying to calculate this:
>
> ----------------------------------------------------------------------------------------------
> >> z
>
> z =
>
> 2.225167162095353e+003 -9.020383145678592e+002i
>
> >> exp( i*z )
>
> ans =
>
> Inf + Infi
> ----------------------------------------------------------------------------------------------
>
> Yes, I know that exponentials grow fast, but I'd like to find an exact number.
>
> Thanks

Subject: How do I increase the precision of MATLAB?

From: John D'Errico

Date: 10 May, 2012 03:23:21

Message: 16 of 16

"Pavel Holoborodko" <pavel@holoborodko.com> wrote in message <jof56j$qo9$1@newscl01ah.mathworks.com>...
> You can also try Multiprecision Computing Toolbox for MATLAB: http://www.advanpix.com/
>
> For example, your computations done with 50 decimal digits accuracy:

Well, although HPF does not support complex arithmetic,
(I do need to do that part soon enough) it is still doable
without trouble.

exp(a+bi) = exp(a)*(cos(b) + i*sin(b))
 
DefaultNumberOfDigits 50
a = hpf('2.225167162095353e+003');
b = hpf('-9.020383145678592e+002');

exp(a)*cos(b)
ans =
-2.1972691444446757080302623609713964558433334716309e966

exp(a)*sin(b)
ans =
9.3215972111397507416461983734140397970718603473401e965

To verify those results...

exp(sym('2.225167162095353e+003 -9.020383145678592e+002*sqrt(-1)'))
ans =
- 2.1972691444446757080302623609714e966 + 9.321597211139750741646198373414e965*i

John

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us