Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: To plot the graph using Matlab!
Replies: 0

 wright Posts: 1 From: Malaysia Registered: 1/11/11
To plot the graph using Matlab!
Posted: Jan 11, 2011 11:50 PM

Any one can help? Actually i think to using program below to plot out the full graph in Matlab, but don't know which of the part was going wrong and it only can show out the outer part . Please help me ...

Gmin=0.0;
Gmax=2.0;

S(1)=0.0;
S(2)=0.0;
n=1000;
jmax=100;

del=(Gmax-Gmin)/jmax;

tq = 0.1;
G = zeros(1, jmax);
H = zeros(jmax, 100);

% iterate for value a fixed value of G
for j=1:jmax
% set up initial conditions
i = zeros(1,2);
i(1) = 1;
i(2) = 1;
position = zeros(1,2);
T = zeros(2, 1100);
T(1,i(1)) = 1.0;
T(2,i(2)) = 2.0;

k = 2;
ik = 1;

G(j)= (j-1)*del+Gmin; % current value of G

% do n trips for current value of G
while i(1) <= 1000
position(1) = position(1) + tq*(1 + S(1));
T(1, i(1)+1) = T(1, i(1)+1) + tq*(1 + S(1));
position(2) = position(2) + tq*(1 + S(2));
T(2, i(2)+1) = T(2, i(2)+1) + tq*(1 + S(2));

if (position(1) >= 1)
T(1, i(1)+1) = T(1, i(1)+1) + G(j)*(T(k, ik) - T(1, i(1)));

if (i(1) > 900)
H(j,i(1)+1)= T(1, i(1)+1) - T(2, i(2));
end
i(1) = i(1) + 1;
T(1, i(1)+1) = T(1, i(1));
k = 1;
ik = i(1);
position(1) = 0;
end
if (position(2) >= 1)
T(2, i(2)+1) = T(2, i(2)+1) + G(j)*(T(k, i(k)) - T(2, i(2)));
i(2) = i(2) + 1;
T(2, i(2)+1) = T(2, i(2));
k = 2;
ik = i(2);
position(2) = 0;
end
end
end

plot(G,H,'r.','MarkerSize',4)