Abolfazl
Abolfazl

Reputation: 453

Equivalent formulas give different results in MATLAB

One of my friends asked me why simple equivalent formulas get different results. Excuse me that the code is a bit long but the interesting part is just line 99 and 100. Here is the formulas and the code. I checked the code. The problem is where f = 1. The problem is line 99 and 100. It takes about 10 s to run the code. Thanks for any guide or comment.

Upvotes: 0

Views: 59

Answers (1)

eulerleibniz
eulerleibniz

Reputation: 281

Simple. It is just because of round off errors. What you have commented out has some round off errors which makes fplus~=1, so:

E = log( (1 - 1") / 1) >= log(eps) >= -36.0437. 

while the real value should be:

E = log( (1 - 1) / 1) = log(0) = -Inf

Upvotes: 1

Related Questions