Random Numbers in Matlab – Part III

This is the final post in our series on random numbers in Matlab. In the first post, we discussed basic random number functions, and in the second post, we discussed the control of random number generation in Matlab and alternatives for applications with stronger requirements. In this post, we will demonstrate how to create probability distributions with the basic rand and randn functions of Matlab. This is useful in many engineering applications, including reliability analysis and communications.

Continue reading

Random Numbers in Matlab – Part I

In this series of posts, I will explain how to use the various random number generation functions in Matlab. This will include the usage of the basic commands, how to control random number generation, how to create other distributions from the basic functions that Matlab provides, and what alternatives there are to the functions used in Matlab. In this post, I will explain the basic random number generation commands in Matlab, including randrandnrandi, and randperm, and provide some example applications.

Continue reading

Best Practices for Scientific Computing

In lieu of the holiday season, Matlab Geeks is going to take a small break from writing Matlab code. Instead, we’d like to share this great article on the best practices for scientific computing. Increasingly, scientists are writing computer programs to perform their research. However, most scientists only have rudimentary training in computer programming and do not know how to create efficient, reliable, and maintainable code. This brief article lists ten recommendations that can help increase the productivity of scientists and engineers. We have summarized the main points of the paper in this article. We try to use these recommendations ourselves and believe the dissemination of this knowledge will help the scientific computing community become more productive.

Original article

Continue reading

Floating Point Comparisons in Matlab

A common problem in Matlab and every other programming language that uses floating point numbers is that calculations involving floats often do not yield the expected answers because of rounding, which can have undesirable effects on control statements. The immediate question is how to handle these rounding errors so that intuitively correct statements are recognized as true by a program. We would like to accomplish this while still retaining as much relevant information in the numbers as possible, thereby allowing the detection of minute differences that are not artifacts of rounding. In this post, some common errors in floating point comparisons will be discussed, as well as methods of handling these errors.

Continue reading

Conversion of Floating Point Numbers from Binary to Decimal

After introducing floating point numbers and sharing a function to convert a floating point number to its binary representation in the first two posts of this series, I would like to provide a function that converts a binary string to a floating point number. In addition. I will convert between different types of binary representations and discuss their merits.

Continue reading

Conversion of Floating Point Numbers in Matlab

In the last post on floating point numbers, I presented a brief overview of floating point numbers, introduced several Matlab functions that provide information about floats (realmin, realmax, and eps), and explored the workings of eps. In this post, I would like to introduce a function that I wrote in Matlab to convert a floating point number to its binary representation and use that function to explain the floating-point representations of ten different numbers.

Continue reading

Floating Point Numbers in Matlab

Floating point numbers are utilized in most calculations performed in Matlab and other programming languages. Often misunderstood, floating-point arithmetic can cause many confounding problems in addition, subtraction, multiplication, division, comparison, and other types of calculations. In this series of posts, I would like to describe the basics of floating point numbers that conform to  IEEE Standard 754 , introduce several Matlab functions that provide information about floating point numbers, provide a pair of functions that convert between the decimal and binary floating point representations, present some examples of how to view floating point numbers in different formats, and demonstrate how to handle some common problems with their arithmetic. In this post, I will give a brief overview of floating point numbers, introduce several Matlab functions that handle floats, and delve into detail of one of these functions named eps.

Continue reading