Integer usually 2 bytes one bit reserved for the sign Then the absolute v alue of an inte ger is at most 2 15 1 32 767 Often also double integers 4 bytes Largest value 2 31 1 2 147 483 647 brPage 2br Real number usually 4 bytes sign coef64257cie ID: 33493
Download Pdf The PPT/PDF document "Basicconceptsofnumericalmethods Number r..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
BasicconceptsofnumericalmethodsNumberrepresentationsThesmallestaddressableunitisusuallyan8bitbyte(exceptinsomewordbasedma-chines,likeCray).Integer,usually2bytes,onebitreservedforthesign.Thentheabsolutevalueofaninte-gerisatmost215 1=32767.Oftenalsodoubleintegers,4bytes.Largestvalue231 1=2147483647. Realnumberusually4bytes.-sign-coecient(mantissa),normalizedintherange0.1{1-exponent:sign+absolutevalueor2'scomplementE.g.onaPCthemantissaofasingleprecisionrealnumberconsistsof23bits.Thebitfollowingthedecimalpointisalways1,andneednotbestored.Precision24bitsorlog102247decimals.Exponentpart8bits,e=127(bias)+trueexponent;1e254.Rangeofvalues2 12610 38{212831038.Doubleprecision:abouttwiceasmanysignicantdigitsandwiderrangeofvalues.OnaPCtheprecisionisabout15decimals,andrangeabout10 308:::10308.(Ifthisrangeisnotsucient,youshouldprobablyrethinkyouralgorithm...) FiniteprecisionPrecisionand\roatingpoint(realnumber)representationsaredescribedbymachinecon-stants."Machineepsilon"isthesmallestnumberthataddedtooneproducesasumbiggerthanone:=minfxj1+x1g:OnaPCthemachineconstantofdoubleprecisionrealnumbersis=2:210 16.NB!thisisverymuchbiggerthanthesmallestrepresentablepositivevalue. PC'sandsomeothersystemsusetheIEEEextendedarithmeticthatincludestwospecialvalues,Inf(innity)andNaN(NotaNumber).DivisionbyzerogivesInf,whichcanbe,withcaution,usedinfurthercalculations.How-ever,itindicatesthatthealgorithmisnotquitedecent,andinsomesystemstheprogrammaycrash.Youshouldndthesourceofthepotentialproblem.Operationslike0=0,0InfandInf Infareindeterminate,andthevalueisNaN.Allfur-theroperationswithsuchavaluewillalsogiveNaN.Thatcertainlymeansthatyoural-gorithmisnotworkingproperly. ErrorsIftheexactvalueisa,theabsoluteerrorofitsapproximatevalue~aisa=~a a:Therelativeerrorise=a a=~a a a:Oftenaisnotknown,butacanbeestimatesbye.g.itsstatisticalproperties.Anesti-mateoftherelativeerroristhenea ~a: Rounding:1.4901,1.51.5512,1.61.50022.5002Truncation:theleastsignicantpartofthenumberisdiscarded.ThisisthewayrealnumbersareconvertedtointegersinFortran. ErrorpropagationinarithmeticoperationsAdditionInadditionalsotheerrorsareadded.Ifthesignsoftheerrorsarerandom,theerrorspartlycanceleachothers.1:57+0:76=2:33:Calculatethesumbyroundingthenumberstoonedecimalplace:1:6+0:8=2:4Therelativeerrorsofthetermsare1:6 1:57 1:57=0:019;0:8 0:76 0:76=0:053:Therelativeerrorofthesumis2:4 2:33 2:33=0:030; Therelativeerrorofthesumcanneverexceedthelargestrelativeerrorofthepositiveterms.Changetheexamplealittle:1:57+0:74=2:31:1:6+0:7=2:3Nowtherelativeerrotsofthetermsare1:6 1:57 1:57=0:019;0:7 0:74 0:74= 0:054:Therelativeerrorofthesumis2:3 2:31 2:31= 0:004:Additionisasmoothingoperation,ifthesignsoftheerrorsofindividualtermsareran-dom. Additioncancauseproblemsifthemagnitudesofthetermsareverydierent.Ifthepre-cisionis7decimals,1:0+310 8=1:0.Whenevaluatingalongseriesitmaybeusefultocalculaterstthesumofthesmallestterms,orclumpthetermsintogroupsinsuchawaythatthesumineachgroupisofthesamemagnitude. SubtractionInmathematics,subtractionisnotessentiallydierentfromaddition.Whencalculatingwithniteaccuracythedierenceiscrucial.Twoapproximationsof:1=3:160494and2=3:142857.Expressthevaluesusingthreedecimalsandsubtract:exactvalueapproximateabs.errorrel.error13.1604943.160-0.00049-0.0001623.1428573.1430.000140.000051 20.0176370.017-0.00064-0.03612Therelativeerrorofthedierenceismuchbiggerthantheoriginalerrors,becausethemostsignicantdigitsofthemantissaspartlycanceleachothersleavingasmallernum-berofsignicantdigits(catastrophiccancellation).Bewaresubtractionofnearlyequalvalues! Forexample,whenxissmall,thefollowingexpressionmaygiveproblems:p 1+x 1;Ifx1,thesquarerootcanbereplacedwiththersttermsofitsTaylorexpansion:p 1+x 11+1 2x 1=1 2x:Theexpressioncanalsobeconvertedtoanotherform:p 1+x 1=x 1+p 1+x: Example:ndtheintegralI=10x x+10dxI+1+10I=10x+1 x+10+10x x+10dx=10x(x+10) x+10dx=10xdx=1 +1;whichgivesarecurrencerelationI+1=1 +1 10I: I0=10dx x+10=10ln(x+10)=ln11 ln100:0953:I1=1 1 100:09530:0470;I2=1 2 100:04700:0300;I3=1 3 100:03000:0333;I4=1 4 100:0333 0:0833:????Thedenominatorhasalmostaconstantvalue10;henceI1 1010xdx=1 101 +1:Thustheproblemisthesubtractionofnearlyequalquantities.