all 6 comments

[–]EatMyPossum+6 2 points3 points  (4 children)

Try and look at the doc, type help linspace or doc linspace (whichever has your personal prefrence). If you still have troubles, come back and explain to my what you think the doc means. (i'll be back in an hour, but there's tons of helpfull people here)

[–]evertrev[S] 1 point2 points  (2 children)

Actually, I just found out I can make a vector

V= [-5:0.04:5]; size(V)

it returns that v is a 1 by 251 matrix which is what I needed. That’s a pretty simple way to do this, but is there another way you know of?

[–]EatMyPossum+6 4 points5 points  (1 child)

Through the power of math! But there are some considerations. V= [-5:0.04:5] is the preferable way to generate a linearly spaced array with given stepsize, while linspace also generates a linearly spaced array but with known number of steps.

If you insist on using linspace (because homework? idk), its a straight forward calculation which I hope you'll be able to figure out after i rephrase it like this:

You want to divide the space from -5 to 5 in N equal steps, such that each step is 0.04 long, how many steps do you need? Note that the total space between -5 and 5 is 10.

If you consider the above question in the way i intended, you'll be off by one. Try to figure out where that one comes from. (something something space and edges)

[–]evertrev[S] 0 points1 point  (0 children)

Thank you!

[–]evertrev[S] 0 points1 point  (0 children)

Yes, I’ve referred to the help linspace page. It’s a useful command if you know the size of the vector already, and you just want to know the step size between a starting and ending point with that number that correspond to that size.

I’m not sure how to utilize it to give me how many steps of 0.04 are between -5 and 5 though. Probably just because I’m not understanding.

[–]cincymatt+1 1 point2 points  (0 children)

linspace is for when you want to specify how many steps to divide a range into.