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

The Archive Base Latest Questions

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

Matlab code: invD = inv(D); Dew=2*invD-E; D is 1000×1000 matrix of complex numbers. It

  • 0

Matlab code:

invD = inv(D);
Dew=2*invD-E;

D is 1000×1000 matrix of complex numbers. It inverts in 0,5 sec or less.

I tried several ways of porting this code to C++, using different approaches, but it is always slower than 10 seconds. What am I doing wrong? How possibly Matlab optimizes that code?

I did’t write this matlab code, I just have to port it. Sorry, I’m much better in coding that in math.

  • 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-18T04:07:11+00:00Added an answer on June 18, 2026 at 4:07 am

    I am fairly sure you are using Eigen incorrectly. I tried inverting a random 1000×1000 matrix with octave (free alternative to MATLAB, probably slightly less optimized) and with the following Eigen code. Octave takes about 1s, Eigen about 1.5s (I’m using boost::timer instead of your timing solution, but only because it’s less of a hassle):

    #include <iostream>
    #include <Eigen/Dense>
    #include <boost/timer/timer.hpp>
    
    using Eigen::MatrixXcd;
    
    int main() {
        MatrixXcd m,mi;
      {
        boost::timer::auto_cpu_timer t;
        m = MatrixXcd::Random(1000,1000);
      }
      {
        boost::timer::auto_cpu_timer t;
        mi = m.inverse();
      }
        std::cout << mi(4,4) << std::endl;
    }
    

    The first possible culprit I can think of are compiler options. Did you compile your C++ code with -O2 at least?

    There is still a possibility that your matrices have a special structure, so that numerical considerations make the Eigen algorithm slower in your particular case, but I would look elsewhere for the problem before considering that.

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

Sidebar

Related Questions

Here is my MATLAB code: [numeric, pics] = xlsread('matrix.xls'); [r,c] = size(pics); done =
I have written a matlab code which would load the matrix written in a
I've got MATLAB code inserting n-dimensional points (n >1) into a matrix ( myPointMatrix
In the following matlab code, random_numbers = randn(1,1000); j=1; for i=1:length(random_numbers) if random_numbers(i) >
Is there Matlab code that shows a series of numbers representing a waveform as
I have the following matlab code: randarray = gpuArray(rand(N,1)); N = 1000; tic g=0;
I'm trying to write a Matlab code that, given a matrix, outputs 3 matrices
My matlab code does image processing, and I made matlab function which has 2
Problem in MATLAB Code for solving desired 'n' number of simultaneous equations of the
For some MATLAB code that I want to make executable, I need the location

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.