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:
Verify if a matrix is upper triangular. Also if it is lower triangular

Subject: Verify if a matrix is upper triangular. Also if it is lower triangular

From: Edwardo

Date: 24 Nov, 2012 19:57:07

Message: 1 of 5

Hi!

I am a new Matlab user, and I want to test if a matrix is upper or lower triangular. Something like : isupper(mat) and islower(mat)
Can someone tell me if there exits functions already fot this?
If not, can someone help me to build functions for this?

Thanks!

Subject: Verify if a matrix is upper triangular. Also if it is lower triangular

From: Roger Stafford

Date: 24 Nov, 2012 20:17:08

Message: 2 of 5

"Edwardo " <edwardo.rivera@upr.edu> wrote in message <k8r8qj$ljq$1@newscl01ah.mathworks.com>...
> ..... I want to test if a matrix is upper or lower triangular.
- - - - - - - -
  Let A be a square matrix. It is upper triangular if

 all(all(tril(A,-1)==0))

is true.

Roger Stafford

Subject: Verify if a matrix is upper triangular. Also if it is lower triangular

From: dpb

Date: 24 Nov, 2012 20:21:02

Message: 3 of 5

On 11/24/2012 1:57 PM, Edwardo wrote:
> Hi!
>
> I am a new Matlab user, and I want to test if a matrix is upper or lower
> triangular. Something like : isupper(mat) and islower(mat)
> Can someone tell me if there exits functions already fot this?
> If not, can someone help me to build functions for this?
>
> Thanks!

Simple enough...

r = function istriu(z)
   r=all(all(z==triu(z)));

extension should be obvious... :)

--

Subject: Verify if a matrix is upper triangular. Also if it is lower triangular

From: Edwardo

Date: 25 Nov, 2012 00:04:08

Message: 4 of 5

"Roger Stafford" wrote in message <k8ra04$pab$1@newscl01ah.mathworks.com>...
> "Edwardo " <edwardo.rivera@upr.edu> wrote in message <k8r8qj$ljq$1@newscl01ah.mathworks.com>...
> > ..... I want to test if a matrix is upper or lower triangular.
> - - - - - - - -
> Let A be a square matrix. It is upper triangular if
>
> all(all(tril(A,-1)==0))
>
> is true.
>
> Roger Stafford

Hi, I made this:


function res = isupper(A)
res = isequal(A,triu(A)); # verify if A is equal to the upper triangular matrix A. store the result in res.
end

function res = islower(A)
res = isequal(A,tril(A));# verify if A is equal to the lower triangular matrix A. store the result in res.
end

this is ok right?

Subject: Verify if a matrix is upper triangular. Also if it is lower triangular

From: dpb

Date: 25 Nov, 2012 00:58:12

Message: 5 of 5

On 11/24/2012 6:04 PM, Edwardo wrote:
> "Roger Stafford" wrote in message
> <k8ra04$pab$1@newscl01ah.mathworks.com>...
>> "Edwardo " <edwardo.rivera@upr.edu> wrote in message
>> <k8r8qj$ljq$1@newscl01ah.mathworks.com>...
>> > ..... I want to test if a matrix is upper or lower triangular.
>> - - - - - - - -
>> Let A be a square matrix. It is upper triangular if
>> all(all(tril(A,-1)==0))
>>
>> is true.
...

> function res = isupper(A)
> res = isequal(A,triu(A)); ...

...[lower elided for brevity]...

> this is ok right?

That's identically the logic I used except for isequal() instead of
all() and ==

Nicer form, actually to eliminate the nested ALL's...

--

Tags for 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