## A MATHCOUNTS problem solution via abstraction

_________________

This post is brought to you by

Holistic Numerical Methods Open Course Ware:

the textbooks on

the Massive Open Online Course (MOOCs) available at

## Unexpected zeros error in MATLAB in zeros function

YouTube Comment: This MATLAB program gives me an error.  W=2.4; L=3; Delta=0.6; i=(W./Delta)+2; j=(L./Delta); T=zeros(i,j); . When I write 0.1 for Delta, there is an error for zeros statement.

Answer: When writing a new program, avoid using the semicolon as it suppresses the output. Write each line separately in a .m file and run the mfile. That way you would have noticed that “i” is turning out to be a real number. It shows up as 26.0000 but if you use format long statement, you will see that you get 25.999999999999996. You can round(i) and round(j) to the nearest integer. The reason “i” turns out to be 25.999999999999996 is because of roundoff error, as numbers and calculations get represented in binary format.

_________________________________________________________________________

This post is brought to you by

• Holistic Numerical Methods Open Course Ware:
• the textbooks on
• the Massive Open Online Course (MOOCs) available at