Why dont matlab answers match theoretically calculated answers?
2 views (last 30 days)
Show older comments
Hi,
Ive been asked to explain why the answers I obtain from MATLAB of the step and impulse response is different from the mathematical equations/solutions. Any ideas why there is a difference??
0 Comments
Accepted Answer
Walter Roberson
on 5 May 2016
MATLAB does not use infinite precision like theoretical calculations do.
2 Comments
Walter Roberson
on 5 May 2016
As a quick example:
Suppose you add 1/1 + 1/2 + 1/3 + 1/4 + 1/5 and so on, using double precision arithmetic. You reach 10^16 and you add it in. And then every result beyond that is less than 1/10^16 and so adding it on cannot have any effect on double precision numbers that exceed one, since the smallest difference between adjacent representable double precision numbers is about 1E-16. You could keep going as long as you liked, but each additional entry would add a value too small to alter the floating point sum. From this you deduce that the sum of 1/N for N = 1 to infinity must be the sum you have reached -- because additional terms cannot change the value.
But the sum of 1/x is something you might recognize from calculus: sum(1/x) is like integral(1/x) from 1 to x, and integral(1/x) from 1 is ln(x) . So by adding double precision values and seeing that the sum cannot change and deciding that we are done, we are implicitly declaring that ln(x) for x > 10^16 is the same as ln(10^16), since the sum cannot change with the small additions. But! we know that ln(infinity) is infinity: somehow all of those 1/x contributions past what double precision can represent, add up to infinity.
You can make these kinds of calculations in theory and get exact answers, but once you start making the calculations in practice, you need to be very careful. Such as doing the sum from the smaller terms towards the larger ones so that the smaller terms have a chance to accumulate without being overwhelmed by the 1E-16 finite precision if you started from larger terms to smaller.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!