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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:32:22+00:00 2026-05-21T20:32:22+00:00

EDIT: Thank you @yoda and @morispaa. You are both right and @morispaa’s solution works,

  • 0

EDIT:

Thank you @yoda and @morispaa. You are both right and @morispaa’s solution works, i.e. my processing of the transformed coefficients, which is based on assumptions about the space spanned by Z, and the order and "orientation" of the Z vectors, renders the correct result if I update the sign of the columns of Q so that the diagonal of R has positive elements.

For more details about the transformation I am working on you can read this; Z below = sampled Zernike polynomials, which are known for not being orthogonal nor complete on the discrete case (our case).

Intuition on why the solution proposed by @morispaa works. I would love to hear your input about it:

My intuition is that somehow enforcing real non-negative diagonals in R renders a basis Q that "aligns" better with the vectors in Z (which, as I said earlier, is non-unitary), and therefore the Options 1 and 2 below, even though they represent different transformations, output coefficients probably in a similar space.

More specifically, I think Z is "almost" unitary, and maybe this leads the QR decomposition to return a basis that is close enough to Z? Only then I can imagine that my processing of the transformed coefficients, which is based on assumptions about the specifics of the vectors in Z, work when the diagonal of Q is fully positive, but not when it has negative entries. What do you think?

Background

I have both MATLAB R2011a and R2010b installed on my machine.

One of the changes from R2010b to R2011a affects the implementation of qr() (see the release notes about this particular change here).

An important part of one my projects uses qr() to estimate an orthogonal basis for a direct and inverse transformation. My code applies this transformation to an input signal, processes the transformed coefficients and returns back the processed signal. In other words, the changes made in R2011a to qr() made the block that process the coefficients of this transformation to stop working (the inverse transformation does not return the expected inverse transformation of the processed signal).

Somehow the Q matrix that is now returned from qr() is different from the older version in a way that prevents the processing of the transformed coefficients from working properly.

First question

In light of the above, is it possible to tell R2011a to use qr() from R2010b?

Second question

I use Q and Q’ to compute the direct and inverse transformation; you can see more details here. More specifically, I use y = Q * x and x = Q’ * y to compute the direct and inverse transformation respectively. A different way to compute the direct transform is using least squares. In other words we have two options:

Option 1: Direct and inverse transform using QR factorization:

% Direct:
[Q R] = qr(Z);
y = Q' * x;

% Some processing of the y coefficients
% ...

% Inverse:
x = Q*y;

Option 2: Direct and inverse transform via least squares fitting

% Direct:
y = Z \ x;

% Some processing of the y coefficients
% ...

% Inverse:
x = Z*y;

where our variables are:

% x = Input vector
% y = Direct transformation of x
% Z = Matrix with sampled basis

In R2011a the Option 1 above stopped working (it works in R2010b). I really like the idea of using qr() for the direct and inverse transform (it’s much faster than computing least-squares for every new vector). If I wanted to use the new qr() for my project, does anybody know how to make my transformation work again with the new Q?

  • 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-05-21T20:32:22+00:00Added an answer on May 21, 2026 at 8:32 pm

    In a QR factorization as A=QR, R is an upper-triangular matrix. If your matrix A is invertible, then the factorization is unique if you impose the condition that R has real, non-negative diagonals. If this condition is relaxed, you get an orthogonal matrix Q and an upper-triangular matrix R, but they needn’t be unique.

    The non-uniqueness of decompositions often confuses people, and I thought I’d point you to one of my favorite examples: the eigenvectors of an identity matrix.

    From the link you provided:

    Compatibility Considerations:
    Since the
    QR factorization is not unique, these
    different results are still correct.
    Ensure that your code does not depend
    on the values of the elements of the
    factors Q and R.

    Is this what’s happening with your code? Does it depend on the form of Q and R?

    As a quick fix, could you try this from R2010b:

    which qr.m

    On my machine, I get /Applications/MATLAB_R2010b.app/toolbox/matlab/matfun/qr.m. Could you try copying this function and putting it in your R2011 path, and rename it as qr2010 or something? Then whenever you need the old function, you can call qr2010 from the latest version of MATLAB and it should use the old algorithm. I haven’t tested this, so let me know if it works.

    EDIT

    I installed R2011a on my machine and checked out qr. Like I said, not enforcing the positive diagonals will result in different combinations for the signs of the elements, thereby rendering the solution non-unique. However, the forward and inverse transformations should work and it does so on my machine.

    A=magic(5);x=(1:5)';   %'
    [Q R]=qr(A);
    y=Q'*x;                %'
    z=Q*y;
    
    z'
    
    ans =
    
        1.0000    2.0000    3.0000    4.0000    5.0000
    

    I get the same result in both R2011a and R2010b. So, my guess is somehow you’re relying on the diagonals being positive, which is probably not a good thing to do.

    But if you want to retain your code, but instead get the new qr to return the same matrices as in R2010b, then you should use morispaa’s suggestion.

    EDIT 2

    Explanation of morispaa’s solution: Since in 2010b, the diagonals of R are positive to get the same behavior in 2011a, all you need to do is get the sign of the diagonals and propagate it throughout the R matrix. For my example above, R is

    R =
    
      -32.4808  -26.6311  -21.3973  -23.7063  -25.8615
             0   19.8943   12.3234    1.9439    4.0856
             0         0  -24.3985  -11.6316   -3.7415
             0         0         0  -20.0982   -9.9739
             0         0         0         0  -16.0005
    

    and D is

    D =
    
        -1     0     0     0     0
         0     1     0     0     0
         0     0    -1     0     0
         0     0     0    -1     0
         0     0     0     0    -1
    

    The diagonals of R automatically become positive (it’s as simple as -1*-1=1). Similarly, you propagate the sign in the Q matrix. Note that D*D is simply the square of the elements for a diagonal matrix, and is equal to I, the identity matrix. Hence, we get

     Q2*R2=Q*D*D*R
          =Q*I*R
          =Q*R
          =A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I have fixed all but two warnings now, so thank you all for
Code as reference: http://jsbin.com/aboca3/2/edit In this example above (thank you SLaks) I am truncating
Edit I think there is some confusion, I am not using both of the
EDIT Thank you all for your assistance. I have made the modifications to the
Edit: Thank you for the answers. I am currently working on it!!\ I have
EDIT: Thank you so much for your answers, you really amaze me with so
EDIT: Thank you very much for your responses. I understand this properly now! I
EDIT: Thank you all for your help. I edited my Database class to contain
Dear Fellow Android Developers! EDIT: Thank you all for your answers. I see from
[EDIT] Thank you for your answer, my problem is the following : Module A

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.