simple solution
simple solution
(OP)
why does this only give me one point on the graph ?
thanks
Ren
CODE
t=0;
x=0;
for t=0:0.01:1,
x=(exp(-t)).*((sin(sqrt(3)*t)+cos(sqrt(3)*t)));
t=t+0.01;
end
for t=1.01:0.01:5,
x=(exp(-t)).*((sin(sqrt(3)*t) + cos(sqrt(3)*t))) + (0.866*exp(t-1)).*(sin(sqrt(3)*t));
t=t+0.01;
end
plot(t,x)
x=0;
for t=0:0.01:1,
x=(exp(-t)).*((sin(sqrt(3)*t)+cos(sqrt(3)*t)));
t=t+0.01;
end
for t=1.01:0.01:5,
x=(exp(-t)).*((sin(sqrt(3)*t) + cos(sqrt(3)*t))) + (0.866*exp(t-1)).*(sin(sqrt(3)*t));
t=t+0.01;
end
plot(t,x)
Ren





RE: simple solution
Because you are always storing the value of t and x in the same place t and x get overwritten with the new value each time you go through the loop.
Matlab is designed specifically so you don't have to write this sort of code.
your code should read
CODE
x1=(exp(-t1)).*((sin(sqrt(3)*t1)+cos(sqrt(3)*t1)));
t2=[1.01:0.01:5];
x2=(exp(-t2)).*((sin(sqrt(3)*t2) + cos(sqrt(3)*t2))) + (0.866*exp(t2-1)).*(sin(sqrt(3)*t2));
t = [t1 t2];
x = [x1 x2];
clear x1 x2 t1 t2
plot(t,x)
--
Dr Michael F Platten
RE: simple solution
Thanks for your help, i had figured it out in the end. I don't use loops that often (and when I do, I don't need to)
My solution was a little different but yours is better.
Anyways thanks for the help, star for you.
René