Review from Day 1:
basic element of MATLAB is a 1x1 matrix.
operates mostly on columns. To use rows, we need to transpose the
matrices, perform the column operations and then transpose the results
- The ‘:’
operator is one of the most important features of MATLAB: (A(:,4))
draw one circle of radius 1, we used the following code:
- t =
the above code to generate t, looks intuitive, because we know that t’s
values are from 0 to 2*pi and values are separated by pi/100. This gives
us a total of 200 points
- t =
linspace(0,2*pi,200); is another way of executing this statement. “Give me
200 points between 0 and 2*pi”
- If you
want to add another circle of radius 0.5, how would you do it?
- If you
just execute another plot command, the new plot will simply replace the
old plot. You need to type hold on before any subsequent plots. After hold
on, everything else, including the scale, remains the same in the figure.
general statement to plot a circle of radius r centered at y0,x0 is: plot(y0 + sin(t) * r,
x0 + cos(t) * r);
in doubt, use help. For example, help sum gives you some pointers on how
to use the function sum.
- Draw 3
concentric circles at (0,0), one of radius 1, one of radius 0.5 and one of
- On a
different graph draw 4 circles of radius 0.5, at (-0.25, -0.25), (-0.25,
0.25), (0.25, -0.25) and (0.25, 0.25). Hint: to change the x and y limits
of the graph, use axis([xmin xmax ymin ymax]). In this case, try
axis([-2 2 -2 2]) before using hold.
a random 4x4 matrix using a = rand(4,4); Use the sum function to calculate
the sum of each column, the sum of each row and the total sum of the
matrix. There are several ways to do this one.
general statement to plot an ellipse is plot(y0 + sin(t) * ry, x0 + cos(t)
* rx); Plot 2 ellipses centered at (2,2). One with the vertical radius
twice the horizontal radius and the other with horizontal radius twice the