Ask your own question, for FREE!
Mathematics 17 Online
OpenStudy (anonymous):

MATLAB help? I figure out part 1.. 1. You’re driving to California, and start at a green light at a velocity of 0 mph. Every 2 seconds your velocity increases by 5 mph. You will reach maximum velocity at t = 60 seconds. a. Create an array for time and an array for velocity. b. Plot the velocity vs. time and label the axes. 2. If Statement: You see a sign for traffic cameras before starting and the maximum speed limit is 75 mph! Create an “if statement” within a “for loop” that will change any velocities above 75 mph to 75 mph. Plot the new velocity vs. time plot. This is how you will

OpenStudy (anonymous):

this is what I got for #1

OpenStudy (anonymous):

All I have to do is add a for loop that checks the velocity array. If any of the numbers in the velocity array are above 75, then it changes that number to 75. The graph will look similar, except it will go straight across once the velocity hits 75. but, i dont know how to do this ^... help???

OpenStudy (anonymous):

@jim_thompson5910 help? please ;/

jimthompson5910 (jim_thompson5910):

you would add [m,n] = size(v); max = 75; for i = 1:1:n if( v(i) > max ) max = v(i); end end This basically loops through the vector v (the velocity vector) and it tests to see if any elements in this vector are larger than 75 (the max). If there are any, then the max gets updated to this larger value. If not, then the max remains at 75. note: [m,n] = size(v) gets the size of v which is a 1 x n matrix (matlab looks at everything like a matrix...even vectors)

OpenStudy (anonymous):

do I need to define any variables before adding that ^. Also, do i add it to the end or anywhere in specific?

jimthompson5910 (jim_thompson5910):

let me open up the doc, one sec

OpenStudy (anonymous):

okay.

jimthompson5910 (jim_thompson5910):

when you say "then it changes that number to 75" what do you mean by "that number" ?

OpenStudy (anonymous):

where do you see that?

jimthompson5910 (jim_thompson5910):

you wrote in a post above "All I have to do is add a for loop that checks the velocity array. If any of the numbers in the velocity array are above 75, then it changes that number to 75. The graph will look similar, except it will go straight across once the velocity hits 75. but, i dont know how to do this ^... help???"

OpenStudy (anonymous):

So, you know how in the document, there are numbers that are above 75mph?

jimthompson5910 (jim_thompson5910):

yes

jimthompson5910 (jim_thompson5910):

in the velocity array

OpenStudy (anonymous):

I need a loop that will change any of those "above 75mph" numbers back to 75 mph.

jimthompson5910 (jim_thompson5910):

oh so something like 140 will change to 75 ?

OpenStudy (anonymous):

yeah. because for number 2 any velocity over 75mph is not allowed, 75 mph is the max

jimthompson5910 (jim_thompson5910):

ok one sec

jimthompson5910 (jim_thompson5910):

[m,n] = size(v); for i = 1:1:n if( v(i) > 75 ) v(i) = 75; end end This loops through the vector v and it changes any value over 75 to 75. The vector v is really a matrix of size 1 x n (1 row, n columns)

OpenStudy (anonymous):

where do i add it?

jimthompson5910 (jim_thompson5910):

before you use the vector v (so before you plot the graph of the velocities)

OpenStudy (anonymous):

so before.. V=A*t%find the velocity as a function of time

jimthompson5910 (jim_thompson5910):

no, that's how you find all the velocities if you do it before that line, it will be working with a blank or undefined array

jimthompson5910 (jim_thompson5910):

so after that line, but before you use it to plot

OpenStudy (anonymous):

it says undefined variable of 'v'.

OpenStudy (anonymous):

when i put [m,n]=size(v);

jimthompson5910 (jim_thompson5910):

you're using capital V

jimthompson5910 (jim_thompson5910):

i think it's case sensitive

jimthompson5910 (jim_thompson5910):

so try [m,n] = size(V);

OpenStudy (anonymous):

yeah i got it, lol my mistake. but now its not wanting to end show the data.

jimthompson5910 (jim_thompson5910):

what do you mean

OpenStudy (anonymous):

GOT IT ;D thank you so much!

jimthompson5910 (jim_thompson5910):

ok great, yw

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!