Did I find an efficiency that impulse(), irf(), and expmv() miss?
Show older comments
I'm working on an iterative algorithm that needs to compute C·exp(A·t)·B many times in a loop for continuous-time LTI systems, so runtime matters a lot.
I found that impulse(), expmv(), and irf() were all slower than I needed for diagonalizable systems, so I wrote my own function. I benchmarked it against all three on R2026a, across system orders n=2 to 512 and time vector lengths L=100 to 10000, using randomly generated stable diagonalizable systems with real eigenvalues.

Speedups are substantial for n ≤ 128 (up to 20x) and the method still wins at higher orders when L is large enough. Accuracy is around 1e-11 relative error vs expm ground truth (compared to ~1e-15 for impulse/expmv), which is more than sufficient for my application.
I feel like I am missing something -- maybe 1e-11 is too big of an error, maybe I didn't test it on enough systems, maybe the cost of checking if its an eigendecomposable system (it's O(n^3)) is prohibative, maybe it's just better to use trusted methods? I'd really appreciate it if someone could guide me to the right place on this. Happy to provide more information.
10 Comments
John D'Errico
on 20 Jun 2026
Edited: John D'Errico
on 20 Jun 2026
I know. You don't want to explain your algorithm, because you think you have found something new. And so you have not actually asked a question about MATLAB, just a teaser. But you want help. So you are hoping to use answers as a site where someone who understands these tools fully will help you solve your problem, but keep it offline and private. Answers is not a bulletin board to advertise for offline help.
All we know is you have chosen a scheme that is sufficiently accurate for your purposes, at which point it is faster than the code provided. In that case, good for you, but it is not a question about MATLAB. So if you truly want help, then you need to show the algorithm and the code. Explain what you did. That may get some useful help. Or it may fail to do so, if you do not make your agorithm and code clear enough.
Probably what you need to do is publish your idea in a paper, in a peer reviewed journal, where they will send it out to referees for a response. But if you actually want help on Answers, then you need to post an actual question about MATLAB.
Moses
on 21 Jun 2026
John D'Errico
on 21 Jun 2026
Edited: John D'Errico
on 21 Jun 2026
Then post this as a discussion. Or move it there, to a discussion. There you will expect to see responses in terms of design philosophy. As a question about MATLAB though, this does not fit.
If your question is if it is a goal of MATLAB to return results which are not fully accurate, I think most if not many users will have a hissy fit if supplied code was not as fully accurate as possible, even if the result is faster. For example, would most MATLAB users be happy to see simple computations like 1+2 return a result that is only approximately 3, but done in half the time? How much of a tradeoff in time would most users accept if 1+2 returned 3+/-eps?
In your case, you are willing to accept the tradeoff between accuracy and time. But that is fully your choice, and so it is good for you. Whatever floats your boat is good, for you. What we are not given any way to know is if your scheme is fully robust under the entire potential problem domain. Are there edge cases where your scheme returns garbage, or where it becomes slow as hell? We cannot even guess, since we have been given no information at all. The algorithms in MATLAB have generally been chosen to avoid robustness issues, to be as fast as possible under all circumstances, at least on average, and to be as accurate as possible, overall. You might want to reread the 19 dubious ways references by Cleve. I'd be surprised if your scheme in some way is not included there, in some form.
If it is true that your unknown iterative scheme could be implemented with a relative tolerance, so that others could choose to dial in the tolerance they would accept, this would be more appropriate as a choice of algorithm. But again, we have no clue what is involved, because we don't see your code. And were it true that your code, if pushed to achieve similar precision to the existing tools was now slower then those tools, this would be a problem for many users.
Three rules would seem to exist in these circumstances.
- Complaints will always arise about slow code, but they won't be serious complaints, and everyone always wants code to execute in zero time anyway. (See rule 3.)
- Far more strident complaints will be seen about imprecise code, especially if there is no way to dial down the inaccuracy via a provided tolerance. A fully accurate code to within relative eps will generally be preferred. You MIGHT be able to convince tech support (via a feature request) to include your algorithmic choice as an alternative option to some of those codes, in some future unspecified release. This does occasionally happen. However, that would ABSOUTELY, POSITIVELY require a publication on your part as reference, in some refereed journal. Users of MATLAB often need a citation to back up the results they get. (Again, see rule 3.)
- You will never make everyone happy.
Again, this belongs as a discussion. It is easily moved.
Mathworks' philosophy is to provide robust and accurate algorithms first although performance is also important. You'll see in virtually all if not every release notes specific functions that have improved peformance. Alas and alack! these internal incremental speedups, while maybe impressive when timed individually, tend to have been overwhelmed by the general growth of the overall code base and the new rendering engine and new code base such that interaction and particularly UI response may be significantly slower than earlier releases.
However, for a specific functionality such as this, if you're not concerned about trying to protect some innovation as IP but are interested only in whether the modifications you've made might be beneficial for Mathworks to incorporate, then submit an enhancement proposal to Mathworks as at <Product Support Page>. This would have to have sufficient information included that a knowlegeable developer/analyst could evaluate it in enough depth to be able to recognize if there were possible merit in the idea.
You could try a new thread on the <Discussions> site, but it doesn't get a lot of traffic so odds may not be great, but it definitiely would not be off topic. Again, though, as @John D'Errico (who's the numerial analyst whiz on the forum head and shoulders) says, it'll have to have sufficient detail provided to be able to studied in detail.
John D'Errico
on 21 Jun 2026
Edited: John D'Errico
on 21 Jun 2026
An idea, if you are not willing to publish your idea as that can take some serious effort (I admit to being lazy myself, and my publication days are long since passed so I understand an unwillingness to go that route) is to post your code on the File Exchange. This is usually the preferred place for alternative codes to live. And there are some truly great codes on the FEX, expanding the capability of MATLAB in many ways. It in no way diminishes your idea or your code to have it on the FEX.
Walter Roberson
on 22 Jun 2026
Note that code posted on FEX must adhere to some open-source license or other, so posting to FEX may be incompatible with the goal of protecting Intellectual Property.
John D'Errico
on 22 Jun 2026
Again, this really belongs in a discussion. Whatever.
The question of where/how to distribute your ideas is one with many points of view. I faced it long ago, after spending many years employed by a company who allowed employees to publish, but after a while we found they really preferred we did not. They would rather see we spend that energy obtaining patents, or keep our software efforts privately held. Probably why I decided when I left their presence to distribute my work freely. And that meant to either actively publish, or to use a tool like the File Exchange to distribute my work to anyone who had a use for it. The FEX still offers a form of peer review, in the form of comments and discussions there. It gets your work usable and accessible to the entire MATLAB community.
As far as intellectual property goes, it depends on what you will do with your inventions. If it all stays stuck inside your own mind, then as far as the world is concerned, your privately held work has no value. That leaves me liking the FEX.
"...that that kind of contribution would only really come after a publication "
I wouldn't presume that would be the only way, no. I still suspect there could be a path through the enhancement request/support channel that could engender interest and that Mathworks has sufficient internal mathematical analysis capability to determine whether the innovation is supportable or not.
Enhancement requests/suggestions are evaluated on a preliminary basis and enter an internal database state for tracking and are acknowledged as having been received and at least looked at for desireablility by development team. In a real niche area, it's likely it would linger given that there are very limited resources to bring to bear on an essentially limitless list of things to fix/implement before it might bubble its way to the top. That would also be true of the likelihood of somebody noticing a new algorithm was published; no matter how innovative.
For anybody else working in the same area, the FEX idea of having the code there if you would be comfortable with the pottential licensing and open nature as John suggested is probably the place it would have the best chance of seeing any use; others tend to search there for solutions if they find bottlenecks in areas of current interest/work. Mathworks has been known to use some of those ideas as well...
John D'Errico
on 28 Jun 2026
@Moses ,
If you really think your idea merits inclusion into MATLAB, I would state almost certainly they would not consider it without some sort of peer reviewed reference. Think about it like this: If you are writing your doctoral dissertation, and you get result X, you need to back it up. Your advisor, thesis committee, etc., will insist on it. They do not want to use an ad hoc algorithm that some individual created out of the blue. They want a reference. The same thing applies to someone doing work for perhaps NASA, or some government agency. (Long ago, in my old job, when we did government work, the response was the same. What did you do? Do you have a reference to justify what you did? And since they were paying for the work we did, they can demand references, as they should.)
So if you were to propose to MathWorks that your idea be included in MATLAB, they won't do it purely on just you saying it is good. They need to attach a documented reference to the code saying what was done, and why. Nobody wants to see a result based on not much more than the third hand assertion of someone they don't know, saying, sure, this should work. No problem.
And worse, were The MathWorks willing to add your idea into the MATLAB codebase, who would then need to maintain it, debug it, modifiy it 10 years from now, when some subtle issue was identified? Since you are not a MathWorks employee, it would all fall on them. The MathWorks needs to insure the tools they provide are valid not just now, but pretty much forever as far out as they can see.
All of this means the very best way to get your idea implemented into MATLAB proper would be to
- Get it published in a refereed journal. This tells the world that others have reviewed your idea, and agree with your claims as having some validity. This step is of most importance, and you should take it first.
- Write code implementing it. At this point, you can post it on the FEX. If it is good, then your work will attract comments stating it to be so. A very useful thing here is the FEX codes have their own set of reviews and discussions, where any probems with your idea can be brought into the open. Note that posting on the FEX does NOT preclude your idea being implemented in MATLAB proper.
- If you do not want to post on the FEX, BUT you still think your idea is of value, then you can send in a feature request to tech support. Again, having cited documentation behind the idea is important. As well though, when you give them an idea, if you already have working code, then include that with the feature request. This should greatly increase the chance your idea might someday appear as part of the code base, as it gives them a working implementatino to start from, even though they would want to fullly re-write it. Again, you are not the person who would be maintaining that code, and nobody wants to maintain someone else's code.
- Get a job at TMW. This is probably the very best way to see your ideas implemented, as that way they will have someone inhouse who can maintain the code.
Again, personally, I like the FEX idea very much. At the same time, I recognize that I'm long past caring about the idea of publication, or for that matter, getting my code implemented in MATLAB itself. I'm also totally willing to give all of my work away for free. (You will find that tools like my gridfit code itself have citations in many theses, papers, etc. It is probably my most frequently cited code.) But because of the addons explorer in MATLAB, effectively, ALL of the tools I've posted on the FEX can be part of MATLAB, if someone wants to use them.
Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!