Got Questions? Get Answers.
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:
Plotting Condition Numbers of Matrices Orthog

Subject: Plotting Condition Numbers of Matrices Orthog

From: Ashley Daly

Date: 28 Jan, 2009 16:49:02

Message: 1 of 8

Write a MATLAB program to plot the 1-norm and 2-norm condition numbers of matrices orthog from gallery for orders 100, 200, 300,...,1000. I'm completely lost on how to do this. Can anyone help?

Subject: Plotting Condition Numbers of Matrices Orthog

From: Matt

Date: 28 Jan, 2009 16:54:02

Message: 2 of 8

"Ashley Daly" <kl0vis3000@hotmail.com> wrote in message <glq29u$i54$1@fred.mathworks.com>...
> Write a MATLAB program to plot the 1-norm and 2-norm condition numbers of matrices orthog from gallery for orders 100, 200, 300,...,1000. I'm completely lost on how to do this. Can anyone help?


help cond

Subject: Plotting Condition Numbers of Matrices Orthog

From: Ashley Daly

Date: 28 Jan, 2009 17:09:02

Message: 3 of 8

"Matt " <xys@whatever.com> wrote in message <glq2ja$92m$1@fred.mathworks.com>...
> "Ashley Daly" <kl0vis3000@hotmail.com> wrote in message <glq29u$i54$1@fred.mathworks.com>...
> > Write a MATLAB program to plot the 1-norm and 2-norm condition numbers of matrices orthog from gallery for orders 100, 200, 300,...,1000. I'm completely lost on how to do this. Can anyone help?
>
>
> help cond

I know what condition numbers are and how to figure them out individually. However, I'm not sure how to use the plot feature to do this for two two different norms and 10 different orders.

Subject: Plotting Condition Numbers of Matrices Orthog

From: Ashley Daly

Date: 28 Jan, 2009 17:14:01

Message: 4 of 8

Also, I can't figure out how to plot two different plots on the same graph. Is there a way to tell MATLAB to plot(n,condition number for norm 1) for n=100,200,300,...,1000. Really sorry for all the questions. I've read through the help and through my book on MATLAB, but never having done it before or someone to actually show me is really difficult for me.

Subject: Plotting Condition Numbers of Matrices Orthog

From: us

Date: 28 Jan, 2009 17:21:02

Message: 5 of 8

"Ashley Daly"
> Also, I can't figure out how to plot two different plots on the same graph...

a hint:

     help subplot;
     help axes;

us

Subject: Plotting Condition Numbers of Matrices Orthog

From: Steven Lord

Date: 28 Jan, 2009 17:49:37

Message: 6 of 8


"Ashley Daly" <kl0vis3000@hotmail.com> wrote in message
news:glq3fd$aib$1@fred.mathworks.com...
> "Matt " <xys@whatever.com> wrote in message
> <glq2ja$92m$1@fred.mathworks.com>...
>> "Ashley Daly" <kl0vis3000@hotmail.com> wrote in message
>> <glq29u$i54$1@fred.mathworks.com>...
>> > Write a MATLAB program to plot the 1-norm and 2-norm condition numbers
>> > of matrices orthog from gallery for orders 100, 200, 300,...,1000. I'm
>> > completely lost on how to do this. Can anyone help?
>>
>>
>> help cond
>
> I know what condition numbers are and how to figure them out individually.
> However, I'm not sure how to use the plot feature to do this for two two
> different norms and 10 different orders.

Why don't you show us what you've got so far, so we can see specifically
where you're getting stuck?

--
Steve Lord
slord@mathworks.com

Subject: Plotting Condition Numbers of Matrices Orthog

From: Ashley Daly

Date: 30 Jan, 2009 15:39:02

Message: 7 of 8

This is what I tried doing:

>> x=[100 200 300 400 500 600 700 800 900 1000];
>> y1=[cond(gallery('orthog',100),1) cond(gallery('orthog',200),1) cond(gallery('orthog',300),1) cond(gallery('orthog',400),1) cond(gallery('orthog',500),1) cond(gallery('orthog',600),1) cond(gallery('orthog',700),1) cond(gallery('orthog',800),1) cond(gallery('orthog',900),1) cond(gallery('orthog',1000),1)];
>> plot(x,y1);
>> hold on;
>> y2=[cond(gallery('orthog',100,1),2) cond(gallery('orthog',200,1),2) cond(gallery('orthog',300,1),2) cond(gallery('orthog',400,1),2) cond(gallery('orthog',500,1),2) cond(gallery('orthog',600,1),2) cond(gallery('orthog',700,1),2) cond(gallery('orthog',800,1),2) cond(gallery('orthog',900,1),2) cond(gallery('orthog',1000,1),2)];
plot(x,y2)

I'm not sure if there is an easier way to do this though, but it seems to create a plot.

Another question, gallery('orthog',n,k) requires a k. Do you know if the k makes any difference or if I can just leave it out, but use n)? Also, I keep getting that the 2-norm condition numbers for this matrix = 1, no matter what the order is. That seems a little strange, does anyone know if that is correct? Thanks so much.

Subject: Plotting Condition Numbers of Matrices Orthog

From: Steven Lord

Date: 30 Jan, 2009 16:58:52

Message: 8 of 8


"Ashley Daly" <kl0vis3000@hotmail.com> wrote in message
news:glv6um$4r6$1@fred.mathworks.com...
> This is what I tried doing:
>
>>> x=[100 200 300 400 500 600 700 800 900 1000];
>>> y1=[cond(gallery('orthog',100),1) cond(gallery('orthog',200),1)
>>> cond(gallery('orthog',300),1) cond(gallery('orthog',400),1)
>>> cond(gallery('orthog',500),1) cond(gallery('orthog',600),1)
>>> cond(gallery('orthog',700),1) cond(gallery('orthog',800),1)
>>> cond(gallery('orthog',900),1) cond(gallery('orthog',1000),1)];
>>> plot(x,y1);
>>> hold on;
>>> y2=[cond(gallery('orthog',100,1),2) cond(gallery('orthog',200,1),2)
>>> cond(gallery('orthog',300,1),2) cond(gallery('orthog',400,1),2)
>>> cond(gallery('orthog',500,1),2) cond(gallery('orthog',600,1),2)
>>> cond(gallery('orthog',700,1),2) cond(gallery('orthog',800,1),2)
>>> cond(gallery('orthog',900,1),2) cond(gallery('orthog',1000,1),2)];
> plot(x,y2)
>
> I'm not sure if there is an easier way to do this though, but it seems to
> create a plot.

You define x, but then you don't use that information in generating y1 and
y2. That's inefficient. Try:


x = 100:100:1000;
y1 = zeros(size(x)); % Preallocation; very important for efficiency
y2 = zeros(size(x));
for k = 1:length(x)
    y1(k) = cond(gallery('orthog', x(k)), 1);
    y2(k) = cond(gallery('orthog', x(k), 1), 1);
end
plot(x, y1, 'ro-', x, y2, 'k+:');


Now yes, this uses a loop. That's okay. Almost all of the time the loop
takes will be spent in calculation. [Assigning the scalar values into
elements of y will take a tiny amount of time, but the time to perform that
assignment is insignificant compared to the computation time.]

> Another question, gallery('orthog',n,k) requires a k. Do you know if the k
> makes any difference or if I can just leave it out, but use n)? Also, I
> keep getting that the 2-norm condition numbers for this matrix = 1, no
> matter what the order is. That seems a little strange, does anyone know if
> that is correct? Thanks so much.

Well, the description of the 'orthog' option for GALLERY:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/gallery.html#f84-1000083

indicates that k = 1 is the default, so if you omit it ORTHOG uses k = 1
anyway.

--
Steve Lord
slord@mathworks.com

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