Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:20:03+00:00 2026-06-17T15:20:03+00:00

I typed abs(sin(pi)) into MATLAB. I expected it to give me the absolute value

  • 0

I typed abs(sin(pi)) into MATLAB. I expected it to give me the absolute value of pi, hoping to mitigate the natural rounding error with ‘abs’ (absolute value). I still get a rounding error. What should I do instead and why am I wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:20:04+00:00Added an answer on June 17, 2026 at 3:20 pm

    Floating point numbers are always going to give you problems like this. That’s why it’s common to write:

    if (x - TestValue < 0.000001)
    

    instead of

    if (x == TestValue)
    

    I would recommend trying to round the value down a decimal place or two, using something like this:

    x = floor(x * 1e15) / 1e15;
    

    which rounds x down to the nearest 1e15. You could also use round or ceil. This article has some more information on similar strategies for rounding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I typed this into Clojure REPL (using the enclojure Netbeans plugin): user=> hello, world
I try to use the codes below to get the abs value of a
I have code that computes the absolute value of a custom value type: public
I typed in hg add and I am brand new to mercurial and the
Having typed the question and checked the similar title questions im gonna continue as
The default strongly-typed Edit page in ASP.NET MVC 3 generally exposes all fields for
I just typed the follow to try and get my SharePoint site: $spWeb =
I wonder how dynamically typed languages behave when they found a matching case label.
Akka framework recommends using typed actor only for interacting with external code. However, standard
I have a strongly typed DataTable created with the VS2005/VS2008 DataSet designer. The table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.