design - MATLAB script to generate reports of rounding errors in algorithms -


i interested in use or created script error rounding reports in algorithms. hope script or similar done... think usefull digital electronic system design because it´s neccesary study how accuracy error depending of number of decimal places considered in design. script work 3 elements, algorithm code, input, , output. script show error line line of algorithm code. modify algorith code command roundn , compare error of output. define error

errorrounding = output(without rounding) - output round  

for instance have next algorithm

calculation1 = input*constan1 + constan2 %line 1 of algorithm output = exp(calculation1)               %line 2 of algorithm 

where 'input' input of n elements vector , 'output' output , 'constan1' , 'constan2' constants. n number of elements of input vector

so, put algorithm in script , generated in automatic way next algorithm:

input_round = roundn(input,-1*mdec) calculation1 = input*constant1+constant2*ones(1,n) calculation1_round = roundn(calculation1,-1*mdec) output=exp(calculation1_round) output_round= roundn(output,-1*mdec) 

where mdec number of decimal places consider. script give next message

the rounding error @ line 1 #errorrounding_calculation1 

where '#errorrounding' result of next operation errorrounding_calculation1 = calculation1 - calculation1_round

the rounding error @ line 2 #errorrounding_output 

where 'errorrounding_output' result of next operation errorrounding_output = output - output_round

does know if there similar done, or matlab provides solution deal issues related? thank you.

first point: suggest reading what every computer scientist should know floating-point arithmetic david goldberg. should illuminate lot of issues regarding floating-point computations understand more of intricacies of problem considering.

second point: think problem considering a lot more complicated realize. interested in error introduced calculation due reduced precision rounding. don't realize these errors propagate through computations. consider example:

output = input*c1 + c2 

if each of 3 operands double-precision floating-point number, each have round-off error in precision. bound on round-off error can found using function eps, tells distance 1 double-precision number next largest one. example, bound on relative error of representation of input 0.5*eps(input), or halfway between , next largest double-precision number. can therefore estimate errors bounds on 3 operands follows:

err_input = 0.5.*eps(input);  %# maximum round-off error input err_c1 = 0.5.*eps(c1);        %# maximum round-off error c1 err_c2 = 0.5.*eps(c2);        %# maximum round-off error c2 

note these errors positive or negative, since true number may have been rounded or down represent double-precision value. now, notice happens when estimate true value of operands before rounded-off adding these errors them, perform calculation output:

output = (input+err_input)*(c1+err_c1) + c2+err_c2 %# ...and after reordering terms output = input*c1 + c2 + err_input*c1 + err_c1*input + err_input*err_c1 + err_c2 %#       ^-----------^   ^-----------------------------------------------------^ %#             |                                   | %#    rounded computation                      difference 

you can see precision round-off of 3 operands before performing calculation change output as difference. in addition, there source of round-off error when value output rounded off represent double-precision value.

so, can see how it's quite bit more complicated thought adequately estimate errors introduced precision round-off.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -