Thread Subject: Plotting problem

Subject: Plotting problem

From: Elvin D'Souza

Date: 23 Nov, 2009 21:45:27

Message: 1 of 2

h=0.01;
T=2;
s(1)= -1
k=1
while (k~=201)
    B{k}=[4 (5-5*s(k)); (2.5+5*s(k)) -1];
    s(k+1)=s(k)+h
     [V4,lambda4]=eig(B{k});
     V5= V4(:,1);
     V6= V4(:,2);
     angle = dot(V5,V6)/norm(V5)*norm(V6)
    k=k+1;
end


plot(s,angle,'-r'); % plotting (Figure 1)
title('Figure1: Absolute value of cosine(angle)'); % figure's title,
legend('Absolute value of cosine(angle)'); % legend
axis([-1 1 0 1]);
xlabel('s'); ylabel('cos(angle)'); % and axis label

So, this is my code for plotting. When I plot it ti get a straight line at y =0.8210. The final value of angle is 0.8210. So, the problem is that when I run the loop, I see different values of angle, but when the graph is plotted, it takes angle to be 0.8210 throughout. How do I fix this?

Subject: Plotting problem

From: jrenfree

Date: 23 Nov, 2009 22:07:00

Message: 2 of 2

On Nov 23, 1:45 pm, "Elvin D'Souza" <elvin.dso...@yahoo.ca> wrote:
> h=0.01;
> T=2;
> s(1)= -1
> k=1
> while (k~=201)
>     B{k}=[4 (5-5*s(k)); (2.5+5*s(k)) -1];
>     s(k+1)=s(k)+h
>      [V4,lambda4]=eig(B{k});
>      V5= V4(:,1);
>      V6= V4(:,2);
>      angle = dot(V5,V6)/norm(V5)*norm(V6)
>     k=k+1;
> end
>
> plot(s,angle,'-r'); % plotting (Figure 1)
> title('Figure1: Absolute value of cosine(angle)'); % figure's title,
> legend('Absolute value of cosine(angle)'); % legend
> axis([-1 1 0 1]);
> xlabel('s'); ylabel('cos(angle)'); % and axis label
>
> So, this is my code for plotting. When I plot it ti get a straight line at y =0.8210. The final value of angle is 0.8210. So, the problem is that when I run the loop, I see different values of angle, but when the graph is plotted, it takes angle to be 0.8210 throughout. How do I fix this?

You're not saving angle as a vector. Look in your workspace, it will
say that angle is equal to 0.8210. You need to save it as a 1x201
double vector like you are with s.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com