O'Reilly logo

Programming in MATLAB ® by Ram N. Patel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10

Precision and Errors

After studying this chapter, you should be able to:

  • understand various errors and their sources
  • perform precise computations
  • write MATLAB® code for accurate results

10.1 Introduction

Though in everyday life, numbers are almost exclusively represented using the base 10 decimal system, computers use a base 2 system, which is called binary system. An integer N is represented in an n-bit system as,

 

N = (an−1..aj..a1a0 = an−1 × 2n−1 + a1 × 21 + a0 × 20

where ai′s are only 0 or 1. An example of a binary number in an 8-bits system is as follows:

 

N = (01101101)2 = 0 ×27 + 1 × 26 + 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20

You can determine the binary representation of integers in MATLAB by the command dec2bin ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required