MATLAB Answers

How to define a variable without using syms ?

25 views (last 30 days)
Manchikatla Laxmi Prasanna
Edited: John D'Errico on 5 Jan 2021
I am trying to find out eigen values of a matrix without using builtin command.in this I have to do det(A-lambda*I)==0
for this I have to declare a variable without intializing any value to it.
how can I intialize a variable by not assigning any value to it without using SYMBOLIC MATH TOOLBOX?
can anyone help me to do this
thanks in advance

  2 Comments

KSSV
KSSV on 5 Jan 2021
I don't think this is possible without defining symbolic x. What problem you have to define sym x?
John D'Errico
John D'Errico on 5 Jan 2021
Of course you can use a variable that you have not defined as symbolic. Define a FUNCTION that uses an unknown variable. You can then evaluate said function as you please, and this is what root finders excell at doing.

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 5 Jan 2021
Edited: John D'Errico on 5 Jan 2021
fun = @(lambda) det(A - lambda*eye(size(A)));
fun is a function of the unknown variable lambda. It is a function handle. It has A built into the function handle workspace, so any tool that gets passed the function fun can use it.
Now, you can use a tool like fzero on fun, solving for values of lambda that make fun equal to zero. Note that fzero only returns ONE solution for any time it is called, and you may get different solutions based on different starting values or starting intervals. So you will need to use fzero intelligently.
For example,
A = magic(3)
A =
8 1 6
3 5 7
4 9 2
fun = @(lambda) det(A - lambda*eye(size(A)));
Now you can evaluate fun.
fun(2.5)
ans =
-221.875
Again, what remains for you to do is to understand how to solve the problem, how to pass fun to a root finder, like fzero or fsolve, and to do that multiple times. Or perhaps you will be forced to use your own root finding tool, written for some past assignment.
One hopes that your instructor has not given you a matrix with replicated eigenvalues. That would be a nasty trick to really confuse a student, but then students are there to be confused in the eyes of some people. :)

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by