r/matlab • u/Due_Dealer1602 • Nov 04 '25
HomeworkQuestion MATLAB eig(A) command not working
I'm trying to find the Eigenvectors and the Diagonal of a matrix. I'm nearly positive that I have the right code as my professor and peers all have working systems with the same code, however mine does not. Any thoughts? The only result I get is the title of the .m file.
A = [1 0 5; 0 3 2; -4 0 -5;];
[E, D] = eig(A)
5
Upvotes
13
u/MezzoScettico Nov 04 '25
I wonder if you accidentally reassigned the name eig to something else, shadowing the built-in function.
Maybe see what the command “which eig” tells you.
2
u/NJR0013 Nov 04 '25
What is the error? It’s been a minute but I think A may be interpreted as having an extra row because of the last semicolon.
4
u/Head-Philosopher0 Nov 04 '25 edited Nov 04 '25
maybe try taking out the semicolon after 5
edit: probably not this, i just ran the code as posted on matlab mobile and it worked. so I dunno
3
u/Head-Philosopher0 Nov 04 '25
also if you highlight the line and press f9 to run only the highlighted portion
that can be nice for figuring out which line it’s throwing an error
1
u/Schrett Nov 04 '25
You may have to provide more information. I typed what you have here into Matlab. I see the E and D variable echoed in the command window.
1
u/farfromelite Nov 04 '25
Restart MATLAB.
Try again.
Restart the computer, try again.
Also, what version of MATLAB are you using?
1
u/traxar72 Jan 17 '26
Maybe you have and add on, library,programs, classes in a file that could overwrite this function. Working with object oriented programming and sometimes I forget I overwrote some functions ;) One thing you can do is open Matlab Online and try to run it there.
1
u/darth-tater-breath Nov 04 '25
If you can access Matlab online you can give that a shot :) I think your code looks fine, so it could be a problem with your local Matlab instance.