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 9217265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:35:57+00:00 2026-06-18T02:35:57+00:00

I have created a class Matrix to do mathematical operation on floating point matrices

  • 0

I have created a class Matrix to do mathematical operation on floating point matrices (basic operations, inverse, …).

Floating point precision make it difficult to test them.
Typically, if test the inverse operation, the error can be huge if the determinant of the matrix is close to zero.

How can I do unit testing on these operations?

  • 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-18T02:35:58+00:00Added an answer on June 18, 2026 at 2:35 am

    There are a number of options which may be suitable depending on your goals.

    For each individual output element, you can set the error tolerated in that element based on the input values that contribute to it. (In the case of a compound operation, such as multiplying by a matrix and then multiplying by its inverse, you would still set the tolerance based on all values that contribute to the final value.)

    You can select input matrices for testing that do not have determinants near zero.

    Instead of measuring the errors in individual elements, you can compute the distance the result matrix is from the ideal result and determine whether that distance exceeds your error tolerance. (E.g., subtract the two matrices, sum the squares of the elements, and take the square root. For other notions of “distance” and errors in matrix operations, consider this page.)

    Keep in mind that the purpose of testing is to find errors. This suggests that it is okay to use a very large error tolerance provided the threshold is less than the magnitude of any differences that bugs are likely to cause. That is, consider the types of bugs that may occur in your code: References to the wrong element, references outside of the array, omissions of operations, et cetera. Generally, these errors will cause very large errors in the results. As long as your tests catch these errors, they are accomplishing their purposes.

    Ideally, you would compare the computed result of an operation to the ideal result, rather than inverting the operation and comparing to the original input. If the ideal result is not available, you might compare to a more precisely computed result by using extended precision. If this is not generally available, then you might compare by using sets of prepared well-behaved matrices, such as matrices that have only a few simple elements (e.g, small integers) in assorted places (and zeroes elsewhere). Each test would be repeated using different input matrices, so that combined set of test covers the necessary cases. But each test would have simple outputs with little or no rounding error expected.

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

Sidebar

Related Questions

I have a mathematical matrix class. It contains a member function which is used
So I have a generic Matrix class that I created which has the following
I have to create a class Histogram and make operations on this class. The
I am following the guide at http://guides.rubyonrails.org/association_basics.html and I have created class Customer <
I have created a class which extends View class. public class SplashScreen extends View
I have created a class called Class1, and in another module, I want to
I have created one class as public class FormActivity extends Activity { TextView tv
I have created a class which extends Gallery. There is no onCreate() method in
I have created a class for fetching server-side data in my iOS-App, based on
I have created a class derived from NSImageView. However, the classes's constructor (init) is

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.