×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

simple solution

simple solution

simple solution

(OP)
why does this only give me one point on the graph ?

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)
thanks
Ren

RE: simple solution

I think you need to read up on Matlab. You really have got yourself in a muddle.

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

t1=[0:0.01:1];
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

(OP)
Hi MikeyP,

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é

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources