Manually generating row vectors can be tedious especially if they are very long but fortunately MATLAB has better ways.

mathematics

Description

1.     Generating Row Vectors

 

Manually generating row vectors can be tedious especially if they are very long but fortunately MATLAB has better ways.

 

a)     In this method the Start, Step Size and End values are entered.

 

row_vector  = (  start value : step size : end value )

 

For example,

 

t = ( 0 : .01 : .99 ) generates a row vector from 0 to .99 in steps of .01

 

        i = ( 10 : 5 : 1000 ) generates a row vector from 10 to 1000 in steps of 5

 

If only 2 values are entered the step size is automatically set to 1.

 

j = ( 0 : 1000 ) generates a row vector from 0 to 1000 in steps of 1.

b)    With the linspace command the Start, End and Number of Points (elements) are entered.

 

row_vector  = linspace( start value, end value, number of points)

 

For example,

 

t = linspace( 0, .99, 100 )

generates a row vector from 0 to .99 with 100 points

 

n = linspace( -10, 50, 20 )

generates a row vector from -10 to 50 with 20 points

 

If only 2 values are entered the number of points is automatically set to 100.

 

j = linspace( 0, 1000 )

generates a row vector from 0 to 1000 with 100 points

 

 

 

 

 

2.     Plotting with MATLAB

 

a)     The plot command

 

The plot( x, y ) command plots the y vector (on the y axis) with respect to the x vector (on the x axis). Notice the x axis vector is written first in the command.

 

Examples

 

                               i.            t = linspace( 0, 4*pi)          generates 100 points from 0 to 4π

 

y = sin(t)

 

plot(t, y)     plots 2 cycles of a sine wave


Related Questions in mathematics category