how to get precise conversion in matlab?

2 vues (au cours des 30 derniers jours)
Mudasir Ahmed
Mudasir Ahmed le 22 Déc 2015
Commenté : Mudasir Ahmed le 24 Déc 2015
hi
when i want to convert degrees(89.999999999999668207879992402105) into radians matlab gives 1.5707963267948966192313216916398 value as a output. but when i reverse the process it gives round off figure 90. but i need actual and accurate conversion value not the round off.*
vpa(89.999999999999668207879992402105*pi/180)
ans = 1.5707963267948966192313216916398
but when re-convert back to original form
vpa(1.5707963267948966192313216916398*180/pi)
ans = 90.0
i also change the the number of digits like vpa(1.5707963267948966192313216916398*180/pi,100) etc but observe the same results. kindly help me i will be highly thankful to you for this act of kindness
with best regards mudasir ahmed

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Déc 2015
Every time you use a literal number in MATLAB that is not inside a string, MATLAB is going to evaluate the number as double precision before the Symbolic toolbox gets control. You need to quote your numbers. You should also get in the habit of sym()'ing them
vpa('89.999999999999668207879992402105*pi/180')
vpa('1.5707963267948966192313216916398*180/pi')
but better
vpa(sym('89.999999999999668207879992402105*pi/180'))
vpa(sym('1.5707963267948966192313216916398*180/pi'))
  6 commentaires
Walter Roberson
Walter Roberson le 23 Déc 2015
Modifié(e) : Walter Roberson le 23 Déc 2015
Where are those numbers coming from? What is class(angles) ?
As far as double precision numbers are concerned, 89.999999999999667479426986067257 and 89.999999999999668207879992402105 are the same number, both of them being 89.9999999999996731503415503539144992828369140625 . That is something that cannot be changed with double precision numbers. You need to use some kind of extended precision numbers if you want them to be different, and using extended precision numbers will require a different syntax to enter the numbers.
angles= [
sym('88.25292994445806042220189637777'), sym('89.999999999999667479426986067257'), sym('89.999999999999668207879992402105');
sym('86.472119235585302296157262009321'), sym('89.999999999981123270039862159233'), sym('89.999999999999993121983558088696');
sym('84.665084516953164820028709815801'), sym('89.999988086384753274282238804303'), sym('89.999999999999999806246175977474');
sym('82.83552790044595696067282049508'), sym('89.999999999999991112449117158209'), sym('89.999999999999993100744665396289');
sym('80.986484951716410032164762120977'), sym('89.999999999959332692365063960468'), sym('89.999999999999993122476505390389');
sym('79.121948083059506104642254539888'), sym('89.999999975262684086292374865148'), sym('89.999999975262721970224316791639');
sym('77.244683750911755612284108834821'), sym('89.999999986727214128999425244292'), sym(' 89.999999999999993118675432116');
sym('75.357853348492194774432573472921'), sym('89.999999996394470554515857407735'), sym('89.999999999999993122326059745969');
sym('73.464609154556051725140093954363'), sym('89.999999999999992753073655039909'), sym(' 89.99999999999999312244662902997');
sym('71.567882600107703152375030768898'), sym('89.999999999999992581194507627371'), sym('89.999999999999903122444226118167');
sym('69.670377917650110578302342213061'), sym(' 89.99999999999999253319867704809'), sym('89.999999999999993122506541238628');
sym('67.774518693860294741798881967926'), sym('89.999999999741931635361989813778'), sym(' 89.99999999999999311361444679491');
sym('65.8822150925780553458648880066'), sym('89.999999999999993098178222946334'), sym('89.999999999999993098179444490446');
sym('63.995531641271152333402009895049'), sym(' 89.99999999999998928710524083006'), sym('89.999999999999989287200958233939');
sym('62.11650712167783271029169712539'), sym('89.999999999999992778649497157995'), sym('89.999999999999993114151872373191');
sym('60.248879494097092226691703377443'), sym('89.999999714196263418663102999409'), sym('89.999999714228313385429057755702');
sym('58.403778779168425376458768895025'), sym('89.999999999137259749938314739589'), sym('89.999999999137259749982719609229');
sym('56.981178198306788453173114217814'), sym('89.762868470688394985205767662633'), sym('89.762868476395663591421156348161');
sym('55.797765504938677490457342932495'), sym('89.373318780644193165202171792606'), sym('89.373318781818103518674315233533');
sym('54.587935182089116272733342933166'), sym('88.990431406326516856547028587032'), sym('88.990431406591153148197145112555');
sym('53.354014335890068423930796964625'), sym('88.614043918721599881539781770388'), sym('88.614043920256183958551643928488');
sym('52.102828587990070160284343107814'), sym(' 88.2428950103448063709444005364'), sym('88.242895010344837842115341055113');
sym('50.847370222094078935464371138828'), sym('87.874480590803891405154343446749'), sym('87.874480590804517899382996732148');
sym('49.608305531180989583106115411603'), sym('87.505432535307217476773269948055'), sym('87.505432535865023730893742717288');
sym('48.415797409309773763494041129682'), sym('87.133249369666402388158308284657'), sym(' 87.13324953896692912915248042765');
sym('47.319006419412375441482463740122'), sym('86.762822149627226035956852057888'), sym('86.762822149627228080575948403545');
sym('46.582079859159937061510793780591'), sym('85.719451610184566072659221879479'), sym('87.244618123174325584003266671315');
sym('46.066041618599459232573510370179'), sym('82.026624770981104993564747832309'), sym('89.000000000000003122506798154241');
sym('45.386778108921029448330688915442'), sym('81.056639804856155393782241508934'), sym(' 89.00000000000000312247901974552');
sym('44.810709922770479654022899731807'), sym(' 79.85140653285072910261889475959'), sym('89.000000000000003121517090477509');
sym('44.407994718303529322012130356452'), sym('78.406341220762609832287704998145'), sym('89.000000000000003122506695222577');
sym('44.177863358331681247268470314704'), sym('76.663658074969014950975482110977'), sym('89.000000000000003122362329641815');
sym('43.959810840916627632291752292788'), sym('73.526831898059132595944316095278'), sym('89.000000000000003122504187530516');
sym('43.694419499184883392828891264002'), sym(' 71.75826883167902918068982670604'), sym('89.000000000000003121788745062828');
sym('43.251027741546380039207997137945'), sym('70.234204727031649621801943389907'), sym('89.000000000000003122474996583343');
sym('42.637418116998151402898983978727'), sym('68.912769676021656973403748785698'), sym('89.000000000000003032880353561533');
sym('41.898435136021901434977609783495'), sym('67.773923707251102112336590588202'), sym('89.000000000000003122504697427467');
sym('41.184836475454770526169624685702'), sym('66.903523494547958673973603864466'), sym('89.999999999999833536432947613648');
sym('40.862428381239072388102799260482'), sym('66.084460073179689509157465280485'), sym('89.522829700704316787172015822126');
sym('40.540636516266952240290820560618'), sym('65.126856819772530912519556002545'), sym('88.885960217714551629279716649383');
sym('40.255659784465259598431523791579'), sym('64.179840758641944635799072580719'), sym('88.207464330630301643708029281103');
sym('40.010850945561494237717302179161'), sym('63.241575921375690128896697217686'), sym('87.487400817245291516764549854452');
sym('39.808713467498020600905167414088'), sym('62.310121158268191017439073675237'), sym('86.724205099590538795832209618294');
sym('39.651235699137941154002866223805'), sym('61.387356173012999132998791694196'), sym(' 85.91804512572354531908684362598');
sym('39.538165194430280277915644799375'), sym('60.474250224993075081920867482213'), sym('85.067062469592128985115362682617');
sym('39.466960110666933148365305580884'), sym('59.573532356428610582620723516641'), sym('84.169326156839994722851898365978');
sym('39.432015845884450041682328081975'), sym('58.691141415603703186188852732795'), sym('83.224154081908098098508638307682');
sym('39.423721721040762557018620661906'), sym('57.835912725846163986993181391419'), sym('82.231710005217201980940318929372');
sym('39.427854203804045936737648421399'), sym('57.017100025090666114824479945582'), sym('81.189279997945968027347943050819');
sym('39.42505232601452888509690209578'), sym('56.249739658269332912940637300166'), sym('80.096660166863752270670416837442');
sym('39.390647447196684122821808748718'), sym('55.554432288866649394544143908114'), sym('78.956794112988051435129100678996');
sym('39.295485434138460655069960782315'), sym('54.953114909013826829509310430046'), sym('77.770798037323940758694874186351');
sym('39.106436458825812238377876015907'), sym('54.466546953908171183194461748773'), sym('76.532876400986841674072654241597');
sym('38.793346478561563885338769852014'), sym('54.120399281175709446322937865147'), sym('75.254931673637856533630653734693');
sym('38.330331127711641851815067265581'), sym('53.927323291318870022982211863696'), sym('73.937833541301955656658610212964');
sym('17.088336490954339743320153482257'), sym('49.063555853518496847132695282611'), sym('86.047629575645551833491762427327');
sym('16.138569401829393302518657353023'), sym('47.609081651809559546929063777857'), sym('85.687450126216674276932334350917');
sym('15.006475424769433438288650255401'), sym('45.977935577213604395403971235973'), sym('85.458978723833229830146633948827');
sym('13.619921345600788002490770721217'), sym('44.078709299048245947591214648017'), sym('85.426302992581532156656023919662');
sym('11.8267650623723926497981201656'), sym('41.712142445713757074070877012241'), sym('85.715080131695754408779817641065');
sym('9.2245296243075231345408544818852'), sym('38.299037256485604674692363795935'), sym('86.666411504850157482944820068921');
sym('5.1388074134133179210918029726465'), sym('30.843701804839442708201058844684'), sym('89.000000000000003122351467095414');
sym('28.959785727621613973517205409994'), sym('54.325495430170720034364047354408'), sym('64.413455707717931471957842514634');
sym('27.300263679611003321724553761333'), sym(' 53.40589763966739257758376287618'), sym('64.201206002843651134925162070302');
sym('25.62282243403643143500417851977'), sym('52.123521237961941855752478708157'), sym('64.256742505487985426401814667469');
sym('23.974934495670188034831815641503'), sym('50.610887465555046818907822300253'), sym(' 64.42902804551721983255616881651');
sym('22.393617675833419721572977100908'), sym('48.983754817517843921699882905277'), sym(' 64.58777051075157160282839204065');
sym('20.9136705221437470819555683003'), sym('47.330951777057346264087673835005'), sym('64.649303247434845792310399744472');
sym('19.552736292111277733563303438249'), sym('45.704802598671202874024285901832'), sym(' 64.57638555534845735610850884807');
sym('18.303004911231574024589890716086'), sym('44.115175486918536557716106802083'), sym(' 64.36236010002650130446682268459');
sym('17.162176457503987920893415185285'), sym('42.570027260737358172789268488225'), sym('64.017828883422816119207996253756');
sym('16.120123743171187924138480960379'), sym('41.060901322245796730887839713783'), sym('63.558787904260808428485984774223');
sym('15.166787409098382995826927992926'), sym(' 39.57207210327954701605610969234'), sym('62.999463759677363774229270520181');
sym('14.301439336879539867450684659215'), sym('38.094384784038862633711645600066'), sym('62.354253677110472521393429410139');
sym('13.526832297231141653098236378403'), sym('36.616770587520529103625710863017'), sym('61.634524238867484228443610224466');
sym('12.850501310778781306222068328247'), sym('35.126883705709719841402168873312'), sym('60.848444575878857649176841110459');
sym('12.284397912758216491110610479016'), sym(' 33.60675249292420351290535089423'), sym('59.998875787093948993659901232047');
sym('11.850657253299977011459150618238'), sym('32.043625573573381396489406033223'), sym('59.090265841925510609666078241094');
sym('11.578458542097010605365011465385'), sym('30.422986869093006618461491586559'), sym('58.126530416235207016291855738527');
sym('11.504263485735878495047308258173'), sym(' 28.71572390735581123066212518705'), sym('57.105329541189146473954034925919');
sym('11.678732472807425838154168030856'), sym('26.886189539992739528140603212764'), sym('56.027010863763760399102906686034');
sym('12.181306720144578013295213987822'), sym('24.859896939437277868477685302965'), sym('54.886481012736021475711619783746');
sym('13.184370198537854836016299301885'), sym('22.468617738031179119546537731579'), sym('53.681045085177236860613126547676');
sym('15.642414758797712348570085462682'), sym('18.748259766124868423160203703476'), sym('52.401564526560994561415411772799');
sym('16.9508665100419632846198400422'), sym('16.950866510041963793699713245751'), sym('51.740960676360972733385568307922');
sym('16.498212382502374803847658602886'), sym('16.498212382692138566414870516934'), sym('50.402561559214755262635615502243');
sym('15.919905061949010353340137349393'), sym('15.919905061949010413452495414692'), sym('48.674082816172438711434825843997');
sym('15.183925314231711540908280773759'), sym('15.183925314261638594109821471355'), sym('46.476547248247282760657883572379');
sym('13.412731496284297607231295000985'), sym('13.412731496523672719107295235403'), sym('41.252575359960835968731759787589');
sym('12.714440699371424835588987115622'), sym('12.714440699371426022738711185432'), sym('39.141116126870159748204294086147');
sym('12.186838895206284480010663039331'), sym('12.186838895238221924881752059544'), sym('37.452396542858788255661055148553');
sym('7.600148345944255809874815387914'), sym('15.556265751981246969820316657954'), sym('36.289755985020056214898092792324');
sym('0.0000000000000031922172083790895440123007852701'), sym('17.921422936799498618476457878867'), sym('34.872114308935505260139893222266');
sym('0.000000000000013161458532581005948154928445771'), sym('17.434764669812986472753895945526'), sym('33.670396354896374198562337436628');
sym('0.00000000028643072306544462460669910260623'), sym('16.913669506785211610166569111438'), sym('32.006505847327203996890387585791');
sym('0.00000000025303621218320715713595039830793'), sym('16.561564817383445960663272025325'), sym('30.002218759573927269136189010233');
sym('0.00000000049538621296507250113310323848921'), sym('16.603361740208815054040574393569'), sym('27.558765435517896448831430971234');
sym('0.00000000022796327950043512563397227058782'), sym('17.631108143238673261963545038128'), sym('24.170514514119890139717605257263');
sym('4.018646510795218826538722177555'), sym('19.438461505599588429240452317561'), sym('19.439167200283906564736128157213');
sym('0.0000000000000000031052008141318308720142949148162'), sym('19.653908916254078761677904582833'), sym('19.653908916254078763091318017406]');
Mudasir Ahmed
Mudasir Ahmed le 24 Déc 2015
thank you so much sir :)

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Aucun tag saisi pour le moment.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by