Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
eigen values equation

Subject: eigen values equation

From: Ender

Date: 19 Feb, 2010 16:36:05

Message: 1 of 6

I have a coding problem that I need help with.

I am trying to write code that displays the value of a determinant with eigen values but I need all the equation as simplified as possible then I need MATLAB to store the value of the constant in that equation in a variable.

Here is my example:

syms lamda

% Make the identity matrix
Ident_matrix = lamda*eye(3);

A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];

Result = A-Ident_matrix;

% Find the rho(T-j) value

eq = det(Result)

The form that I want is:
-lamda*(lamda^2-0.625)

Then I would like MATLAB to store the 0.625 in a variable.

I am not sure where in the help menu to go to figure out how to do this.

--Ender--

Subject: eigen values equation

From: Alan Weiss

Date: 19 Feb, 2010 18:28:09

Message: 2 of 6

Ender wrote:
> I have a coding problem that I need help with.
>
> I am trying to write code that displays the value of a determinant with
> eigen values but I need all the equation as simplified as possible then
> I need MATLAB to store the value of the constant in that equation in a
> variable.
>
> Here is my example:
>
> syms lamda
>
> % Make the identity matrix
> Ident_matrix = lamda*eye(3);
>
> A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
>
> Result = A-Ident_matrix;
>
> % Find the rho(T-j) value
>
> eq = det(Result)
>
> The form that I want is:
> -lamda*(lamda^2-0.625)
>
> Then I would like MATLAB to store the 0.625 in a variable.
>
> I am not sure where in the help menu to go to figure out how to do this.
> --Ender--

You are really close. See what happens with the following statements:
s = solve(eq)
and
eq2 = factor(eq)

For s = solve(eq), you can take each solution and substitute lambda = 0
with the subs command to get your "variable."

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: eigen values equation

From: Ender

Date: 19 Feb, 2010 19:28:06

Message: 3 of 6

I don't quite understand what you are saying here:

> For s = solve(eq), you can take each solution and substitute lambda = 0
> with the subs command to get your "variable."

Also, MATLAB did not factor the equation in the form that I am looking for. After typing in eq2 MATLAB outputs:

eq2 =
 
-1/8*lamda*(8*lamda^2-5)

That is not the form that I am looking for. Also, whenever I type lamda = 0 then type in any of my equations MATLAB does not give me the results minus the lamda variable

--Ender--

Alan Weiss <aweiss@mathworks.com> wrote in message <hlml7p$rgm$1@fred.mathworks.com>...
> Ender wrote:
> > I have a coding problem that I need help with.
> >
> > I am trying to write code that displays the value of a determinant with
> > eigen values but I need all the equation as simplified as possible then
> > I need MATLAB to store the value of the constant in that equation in a
> > variable.
> >
> > Here is my example:
> >
> > syms lamda
> >
> > % Make the identity matrix
> > Ident_matrix = lamda*eye(3);
> >
> > A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
> >
> > Result = A-Ident_matrix;
> >
> > % Find the rho(T-j) value
> >
> > eq = det(Result)
> >
> > The form that I want is:
> > -lamda*(lamda^2-0.625)
> >
> > Then I would like MATLAB to store the 0.625 in a variable.
> >
> > I am not sure where in the help menu to go to figure out how to do this.
> > --Ender--
>
> You are really close. See what happens with the following statements:
> s = solve(eq)
> and
> eq2 = factor(eq)
>
> For s = solve(eq), you can take each solution and substitute lambda = 0
> with the subs command to get your "variable."
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Subject: eigen values equation

From: Alan Weiss

Date: 22 Feb, 2010 12:59:41

Message: 4 of 6

Sorry, I misspoke. Here's what I meant:

%Your setup
 >> syms lamda
 >> Ident_matrix = lamda*eye(3);
 >> A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
 >> Result = A-Ident_matrix;
 >> eq = det(Result);

%solve
 >> s = solve(eq)

s =

                     0
  -(2^(1/2)*5^(1/2))/4
   (2^(1/2)*5^(1/2))/4

%Take the second element for example
 >> s(2)

ans =

-(2^(1/2)*5^(1/2))/4

%square it if you like
 >> s(2)^2

ans =

5/8

Does this help?

Alan Weiss
MATLAB mathematical toolbox documentation

Ender wrote:
> I don't quite understand what you are saying here:
>
>> For s = solve(eq), you can take each solution and substitute lambda =
>> 0 with the subs command to get your "variable."
>
> Also, MATLAB did not factor the equation in the form that I am looking
> for. After typing in eq2 MATLAB outputs:
>
> eq2 =
>
> -1/8*lamda*(8*lamda^2-5)
>
> That is not the form that I am looking for. Also, whenever I type lamda
> = 0 then type in any of my equations MATLAB does not give me the results
> minus the lamda variable
>
> --Ender--
>
> Alan Weiss <aweiss@mathworks.com> wrote in message
> <hlml7p$rgm$1@fred.mathworks.com>...
>> Ender wrote:
>> > I have a coding problem that I need help with.
>> > > I am trying to write code that displays the value of a determinant
>> with > eigen values but I need all the equation as simplified as
>> possible then > I need MATLAB to store the value of the constant in
>> that equation in a > variable.
>> > > Here is my example:
>> > > syms lamda
>> > > % Make the identity matrix
>> > Ident_matrix = lamda*eye(3);
>> > > A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
>> > > Result = A-Ident_matrix;
>> > > % Find the rho(T-j) value
>> > > eq = det(Result)
>> > > The form that I want is:
>> > -lamda*(lamda^2-0.625)
>> > > Then I would like MATLAB to store the 0.625 in a variable.
>> > > I am not sure where in the help menu to go to figure out how to do
>> this. > --Ender--
>>
>> You are really close. See what happens with the following statements:
>> s = solve(eq)
>> and
>> eq2 = factor(eq)
>>
>> For s = solve(eq), you can take each solution and substitute lambda =
>> 0 with the subs command to get your "variable."
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation

Subject: eigen values equation

From: Ender

Date: 22 Feb, 2010 16:42:22

Message: 5 of 6

Alan Weiss <aweiss@mathworks.com> wrote in message <hltv3t$ih6$1@fred.mathworks.com>...
> Sorry, I misspoke. Here's what I meant:
>
> %Your setup
> >> syms lamda
> >> Ident_matrix = lamda*eye(3);
> >> A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
> >> Result = A-Ident_matrix;
> >> eq = det(Result);
>
> %solve
> >> s = solve(eq)
>
> s =
>
> 0
> -(2^(1/2)*5^(1/2))/4
> (2^(1/2)*5^(1/2))/4
>
> %Take the second element for example
> >> s(2)
>
> ans =
>
> -(2^(1/2)*5^(1/2))/4
>
> %square it if you like
> >> s(2)^2
>
> ans =
>
> 5/8
>
> Does this help?
>
> Alan Weiss
> MATLAB mathematical toolbox documentation
>
> Ender wrote:
> > I don't quite understand what you are saying here:
> >
> >> For s = solve(eq), you can take each solution and substitute lambda =
> >> 0 with the subs command to get your "variable."
> >
> > Also, MATLAB did not factor the equation in the form that I am looking
> > for. After typing in eq2 MATLAB outputs:
> >
> > eq2 =
> >
> > -1/8*lamda*(8*lamda^2-5)
> >
> > That is not the form that I am looking for. Also, whenever I type lamda
> > = 0 then type in any of my equations MATLAB does not give me the results
> > minus the lamda variable
> >
> > --Ender--
> >
> > Alan Weiss <aweiss@mathworks.com> wrote in message
> > <hlml7p$rgm$1@fred.mathworks.com>...
> >> Ender wrote:
> >> > I have a coding problem that I need help with.
> >> > > I am trying to write code that displays the value of a determinant
> >> with > eigen values but I need all the equation as simplified as
> >> possible then > I need MATLAB to store the value of the constant in
> >> that equation in a > variable.
> >> > > Here is my example:
> >> > > syms lamda
> >> > > % Make the identity matrix
> >> > Ident_matrix = lamda*eye(3);
> >> > > A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
> >> > > Result = A-Ident_matrix;
> >> > > % Find the rho(T-j) value
> >> > > eq = det(Result)
> >> > > The form that I want is:
> >> > -lamda*(lamda^2-0.625)
> >> > > Then I would like MATLAB to store the 0.625 in a variable.
> >> > > I am not sure where in the help menu to go to figure out how to do
> >> this. > --Ender--
> >>
> >> You are really close. See what happens with the following statements:
> >> s = solve(eq)
> >> and
> >> eq2 = factor(eq)
> >>
> >> For s = solve(eq), you can take each solution and substitute lambda =
> >> 0 with the subs command to get your "variable."
> >>
> >> Alan Weiss
> >> MATLAB mathematical toolbox documentation

Thanks, that worked, but know I have a slightly less complicated problem. I need to convert the result back into decimal form. I am using the value for "s" in another calculation however I would like to see the result of that calculation in decimal format. Here is my algorithm:

syms lamda

% Make the identity matrix
Ident_matrix = lamda*eye(3);

A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];

Result = A-Ident_matrix;

% Find the rho(T-j) value

eq = det(Result);

s = solve(eq)
s


rho = s(3)^2
% rho = str2num('s(3)^2')
%
omega =2/(1+sqrt(1-(rho)^2))


I have tried "str2num" and "rats" however "str2num" gives me an empty matrix, and "rats" does not change the format. Is there a fraction to decimal command in MATLAB?

--Ender--

Subject: eigen values equation

From: Alan Weiss

Date: 22 Feb, 2010 17:59:17

Message: 6 of 6

Ender wrote:
> Alan Weiss <aweiss@mathworks.com> wrote in message
> <hltv3t$ih6$1@fred.mathworks.com>...
>> Sorry, I misspoke. Here's what I meant:
>>
>> %Your setup
>> >> syms lamda
>> >> Ident_matrix = lamda*eye(3);
>> >> A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
>> >> Result = A-Ident_matrix;
>> >> eq = det(Result);
>>
>> %solve
>> >> s = solve(eq)
>>
>> s =
>>
>> 0
>> -(2^(1/2)*5^(1/2))/4
>> (2^(1/2)*5^(1/2))/4
>>
>> %Take the second element for example
>> >> s(2)
>>
>> ans =
>>
>> -(2^(1/2)*5^(1/2))/4
>>
>> %square it if you like
>> >> s(2)^2
>>
>> ans =
>>
>> 5/8
>>
>> Does this help?
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation
>>

>
> Thanks, that worked, but know I have a slightly less complicated
> problem. I need to convert the result back into decimal form. I am using
> the value for "s" in another calculation however I would like to see the
> result of that calculation in decimal format. Here is my algorithm:
>
> syms lamda
>
> % Make the identity matrix
> Ident_matrix = lamda*eye(3);
>
> A = [0,-.75,0;-0.75,0,0.25;0,0.25,0];
>
> Result = A-Ident_matrix;
>
> % Find the rho(T-j) value
>
> eq = det(Result);
>
> s = solve(eq)
> s
>
> rho = s(3)^2
> % rho = str2num('s(3)^2')
> % omega =2/(1+sqrt(1-(rho)^2))
>
>
> I have tried "str2num" and "rats" however "str2num" gives me an empty
> matrix, and "rats" does not change the format. Is there a fraction to
> decimal command in MATLAB?
>
> --Ender--

The result s(3)^2 is a symbolic object. Convert it to double with the
"double" command.

Alan Weiss
MATLAB mathematical toolbox documentation

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us