## Matlab

Moderators: None (Apply to moderate this forum)
Number of posts: 2147

This Forum Only

beginner IF construct problem Posted by ikeambiental on 10 Aug 2012 at 7:43 PM
Hello

this is what I'm trying to do:

1. A particle moves in a straight line for 40 s. The velocity as a function of time is: (example)

t<10
v = 2*t

10<=t<=25
v = 1.5*t

25<t<=35
v = 2*t - 20

35<t<=40
v = 10

Create  an M‐file  that  calculates  the  velocity  as  function  of  time  and  plots  the velocity with time. Use if construct.

It's just a question from a textbook for beginners.
What I'm trying to do so far is to declare t = 0:0.1:40 before running the IF, which is not working because whenever I write if t<10 v = 1.4.*t I'm telling the program that when that condition is complied it should multiply 1.4 to the whole "array" t.

I appreciate any help,

Thanks

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic