Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Graph error

0 views
Skip to first unread message

Elvin D'Souza

unread,
Nov 23, 2009, 4:28:06 PM11/23/09
to
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?

Thanks

Darren Rowland

unread,
Nov 23, 2009, 8:03:19 PM11/23/09
to
Change this:
> angle = dot(V5,V6)/norm(V5)*norm(V6)

to
angle(k+1) = dot(V5,V6)/norm(V5)*norm(V6);

It would be better also to preallocate the s and angle vectors outside the loop.

Hth
Darren

0 new messages