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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:12:07+00:00 2026-06-14T04:12:07+00:00

Following is a part of a code I am writing in matlab, here I

  • 0

Following is a part of a code I am writing in matlab, here I want to carry out the following simple mathematical operation [A][X]=[B], where [X] is unknown. In my case I have length of k around 1600000. So all I want is to get the values for g1,g2 and g3 for each element on the array. I have tried the following

k31 = omega3./(d)      
k32 = omega3_2./(d)    
A   = [2,1,5;-2,-1,-5];    
X   = [g1;g2;g3];

for ii = 1:length(k31)    
    B = [k31(ii); k32(ii)];    
    X = pinv(A).*B;    
end

display(g1,g2,g3)

I am using pseudo-inverse so basically I can get a solution for each X and I have made some edit there….and x is unknown, MATHEMATICALLY it can be done, but am not able to code it

Also how do I plot the values of g1 g2 g3 with x and y as follows scatter(x(1:end-1), y(1:end-1), 5, g1); scatter(x(1:end-1), y(1:end-1), 5, g2) and scatter(x(1:end-1), y(1:end-1), 5, g3)

  • 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-14T04:12:09+00:00Added an answer on June 14, 2026 at 4:12 am

    In my opinion you are better off creating a pseudo inverse from the singular value decomposition. Moore-Penrose pseudo inverse will work, but I think it gives some weird results sometimes. The least squares can be unstable, especially since the rank of your example matrix is not full.

    Also; don’t calculate the inverse for every iteration!

    Here is an example, where rank-deficiency of A is taken care of:

    A   = [2,1,5;-2,-1,-5];
    
    % pseudo inverse of A
    [m,n]   = size(A);
    % get SVD
    [U,S,V] = svd(A);
    % check rank
    r       = rank(S);
    SR      = S(1:r,1:r);
    % make complete if rank is not full
    SRc     = [SR^-1 zeros(r,m-r);zeros(n-r,r) zeros(n-r,m-r)];
    % create inverse
    A_inv   = V*SRc*U.';
    
    X=[];    
    for i = 1:1600
        % this actually takes most of the time
        k31 = rand(1000, 1);
        k32 = rand(1000, 1);
        B   = [k31';k32'];
        % X is overwritten on every loop...
        X   = [X A_inv*B];
    end
    
    N_xy = 1000;
    x    = rand(N_xy,1);
    y    = rand(N_xy,1);
    g1   = X(1,1:N_xy);
    
    figure(1), clf
    scatter(x,y,5,g1)
    

    I didn’t plot all 1600000 points since that can’t be what you want

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

Sidebar

Related Questions

The following code is taken from here . I removed all Windows NT part
I have the following code in one cpp file which is part of a
Ok - I have the following code - on the starred part I get
I have the following code, which is run every 10ms as part of a
Using linkedin-j , I have the following code in one part of my application
I'm writing a yacc file as part of a compiler. I have the following
I am following the tutorial here: http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-1 But I'm having trouble with Part 4:
I have the following code FileWriter F = new FileWriter(out.txt); PrintWriter H = new
I have the following code which is part of unit testing for serialization support
following is a part of the code I am writing, for ii=1:length(k31) B =

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.