user3410357
user3410357

Reputation: 11

how to check in between two numbers, if one number is much greater than the other in MATLAB?

While finding roots of a quadratic equation, subtractive cancellation is an issue when b^2 is much greater than 4ac. So, I need to first check whether the given equation has this issue or not. Then if there's an issue, I need to find an alternative way which is to calculate r=-(b+sign(b)*sqrt(delta)) and then we get the roots 2c/r and r/2a. I am struck at checking b^2 is much greater than 4ac.

Upvotes: 1

Views: 83

Answers (1)

Daniel
Daniel

Reputation: 36710

Solutions are:

  1. Use VPA (symbolic toolbox), which is probably the best solution to deal with precision errors on arbitrary calculations.
  2. Use the build in function roots, which deals with this issue very well.
  3. The precision of a double value is known. Based on a required precision, you can define a boundary.

Upvotes: 1

Related Questions