Basic Simulation Lab File (4Mae5-Y)
Basic Simulation Lab File (4Mae5-Y)
TABLE OF CONTENTS
DATE OF DATE OF
S.NO. TITLE OF THE EXPERIMENTS
EXPERIMENT SUBMISSION
EXPERIMENT:1
AIM: Creating a One-Dimensional Array (Row / Column Vector), Creating a Two-
Dimensional Array (Matrix of given size) and
(A). Performing Arithmetic Operations - Addition, Subtraction, Multiplication and
Exponentiation.
(B). Performing Matrix operations - Inverse, Transpose, Rank.
THEORY:
Matrix Addition and Subtraction is performed by merely adding or subtracting the matrix
elements by their corresponding elements in the other matrix.
The inverse of a matrix does not always exist. If the determinant of the matrix is zero,
then the inverse does not exist and the matrix is singular.
Transpose operation switches the rows and columns in a matrix. It is represented by a single
quote(').
Rank function provides an estimate of the number of linearly independent rows or columns
of a null matrix.k = rank(A) returns the number of singular values of A that are larger than the
default tolerance, max(size(A))*eps(norm(A)).
k = rank(A,tol) returns the number of singular values of A that are larger than tol.
MATLAB PROGRAM:-
b=[6,7,5];
h=e+f
%creating one dimensional column matrix
of order 3*1% %performing arithmetic operation-
subtraction%
c=[3;4;5];
i=e-f
d=[5;9;8];
%performing arithmetic operation-
%creating two dimensional row matrix multiplication%
2*4%
j=e*g
e=[2,5,4,5;2,3,9,6] ;
%performing arithmetic operation-
f=[2,3,4,5;2,4,7,6]; exponentiation%
%creating two dimensional column matrix k=2.^a
4*2%
m=0:1:2
g=[2,3;4,5;2,4;7,6] ;
stem(m,k) x=[2,3,4;4,6,5;5,6,7]
p=inv(x)
v=g'
rank(e)
h= k=
4 8 8 10 4 8 16
4 7 16 1 m=
i= 0 1 2
0 2 0 0
0 -1 2 0 x=
j= 2 3 4
67 77 4 6 5
76 93 5 6 7
v=
p= 2 4 2 7
0.6667 -0.3333 0 2
FIGURES
EXPONENTIAL FUNCTION
16
14
12
10
y-axis
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x-axis
CONCLUSION
The given experiment has been performed successfully.
EXPERIMENT:2
An operator is a symbol that tells the compiler to perform specific mathematical or logical
manipulations. MATLAB is designed to operate primarily on whole matrices and arrays.
Therefore, operators in MATLAB work both on scalar and non-scalar data. MATLAB allows
the following types of elementary operations:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operations
5. Set Operations
6. Arithmetic Operators
Matrix arithmetic operations are same as defined in linear algebra. Array operations are
executed element by element, both on one-dimensional and multidimensional array.
The matrix operators and array operators are differentiated by the period (.) symbol.
However, as the addition and subtraction operation is same for matrices and arrays, the
operator is same for both cases. The following table gives brief description of the operators:
Operator Description
Addition or unary plus. A+B adds A and B. A and B must have the same
+
size, unless one is a scalar. A scalar can be added to a matrix of any size.
Subtraction or unary minus. A-B subtracts B from A. A and B must have the
- same size, unless one is a scalar. A scalar can be subtracted from a matrix of
any size.
* Matrix multiplication. C = A*B is the linear algebraic product of the
matrices A and B. More precisely,
For nonscalar A and B, the number of columns of A must equal the number
of rows of B. A scalar can multiply a matrix of any size.
Relational Operators
Relational operators can also work on both scalar and non-scalar data. Relational operators
for arrays perform element-by-element comparisons between two arrays and return a logical
array of the same size, with elements set to logical 1 (true) where the relation is true and
elements set to logical 0 (false) where it is not.
Operator Description
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
~= Not equal to
Logical Operators
MATLAB offers two types of logical operators and functions:
Short-circuit logical operators allow short-circuiting on logical operations. The symbols &&
and || are the logical short-circuit operators AND and OR.
Bitwise Operations
Bitwise operator works on bits and performs bit-by-bit operation. The truth tables for &, |,
and ^ are as follows:
Assume if A = 60; and B = 13; Now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101
-----------------
~A = 1100 0011
MATLAB provides various functions for bit-wise operations like 'bitwise and', 'bitwise or'
and 'bitwise not' operations, shift operation, etc.
The following table shows the commonly used bitwise operations:
Function Purpose
bitand(a, b) Bit-wise AND of integers a and b
bitcmp(a) Bit-wise complement of a
bitget(a,pos) Get bit at specified position pos, in the integer array a
bitor(a, b) Bit-wise OR of integers a and b
bitset(a, pos) Set bit at specific location pos of a
Returns a shifted to the left by k bits, equivalent to multiplying by 2k.
Negative values of k correspond to shifting bits right or dividing by 2|
bitshift(a, k) k|
and rounding to the nearest integer towards negative infinite. Any
overflow bits are truncated.
bitxor(a, b) Bit-wise XOR of integers a and b
swapbytes Swap byte ordering
Set Operations
MATLAB provides various functions for set operations, like union, intersection and testing
for set membership, etc.
Function Description
Set intersection of two arrays; returns the values common to both A
intersect(A,B)
and B. The values returned are in sorted order.
Treats each row of A and each row of B as single entities and returns
intersect(A,B,'rows') the rows common to both A and B. The rows of the returned matrix
are in sorted order.
Returns an array the same size as A, containing 1 (true) where the
ismember(A,B)
elements of A are found in B. Elsewhere, it returns 0 (false).
Treats each row of A and each row of B as single entities and returns a
ismember(A,B,'rows') vector containing 1 (true) where the rows of matrix A are also rows of
B. Elsewhere, it returns 0 (false).
Returns logical 1 (true) if the elements of A are in sorted order and
logical 0 (false) otherwise. Input A can be a vector or an N-by-1 or 1-
issorted(A)
by-N cell array of strings. A is considered to be sorted if A and the
output of sort(A) are equal.
sorted order, and logical 0 (false) otherwise. Matrix A is considered to
be sorted if A and the output of sortrows(A) are equal.
Set difference of two arrays; returns the values in A that are not in B.
setdiff(A,B)
The values in the returned array are in sorted order.
Treats each row of A and each row of B as single entities and returns
the rows from A that are not in B. The rows of the returned matrix are
setdiff(A,B,'rows') in sorted order.
The 'rows' option does not support cell arrays.
MATLAB PROGRAM:-
a= h=
2 4 3 2 3 4 5
5 6 8 8 1 2 0
9 8 7 6 9 3 7
reshaping the matrix
b= g=
2 5 8 2 6 1 4 3 0
5 9 4 8 3 9 2 5 7
4 7 5 rotating a matrix
horizontal concatenation i=
c= 0 7
2 4 3 2 5 8 3 5
5 6 8 5 9 4 4 2
9 8 7 4 7 5 1 9
vertical concatenation 6 3
c= 2 8
2 4 3 flipping a matrix
5 6 8 j=
9 8 7 7 0
2 5 8 5 3
5 9 4 2 4
4 7 5 9 1
indexing two matrices 3 6
d= 8 2
5 5 4 resizing a matrix
9 7 4 g=
5 4 8 2 6 1 4 3 0
sorting row wise g=
f= 2 1 4 3 0
2 4 3 shifting a matrix
5 6 7 k=
9 8 8 0.1875 0.7690 0.6733 0.0594
sorting column wise 0.2662 0.3960 0.4296 0.3158
f= 0.7978 0.2729 0.4517 0.7727
2 3 4 0.4876 0.0372 0.6099 0.6964
5 6 8
7 8 9 l=
0.0372 0.6099 0.6964 0.4876 ans =
0.7690 0.6733 0.0594 0.1875 1 0 0
0.3960 0.4296 0.3158 0.2662 0 0 1
0.2729 0.4517 0.7727 0.7978 1 1 1
m=
using >= operator 1 5
8 0
ans = n=
0 1 1 2 0
1 1 0 0 5
0 0 0 using and operator
using <= operator ans =
ans = 1 0
1 0 0 0 0
0 1 1 using not operator
1 1 1 ans =
using ~= operator 0 0
ans = 0 1
1 1 1 using or operator
1 0 1 ans =
1 1 1 1 1
using >operator 1 1
ans = using xor operator
0 1 1 ans =
1 0 0 0 1
0 0 0 1 1
using < operator
CONCLUSION:-
The given experiment has been performed successfully.
EXPERIMENT:3
THEORY:
VECTORS:
Matrices with one dimension equal to one and the other greater than one are called vectors.
Here is an example of a numeric vector:
A = [5.73 2-4i 9/7 25e3 .046 sqrt(32) 8j];
size(A) % Check value of row and column dimensions
ans =
1 7
We can construct a vector out of other vectors, as long as the critical dimensions agree. All
components of a row vector must be scalars or other row vectors. Similarly, all components
of a column vector must be scalars or other column vectors: A = [29 43 77 9 21];
B = [0 46 11];
C = [A 5 ones(1,3) B]
C=
29 43 77 9 21 5 1 1 1 0 46 11
RANDOM:
rand:
Y = rand(n) returns an n-by-n matrix of random entries.An error message appears if n is not
a scalar.
Y = rand(size(A)) returns an array of random entries that is the same size as A. rand, by itself,
returns a scalar whose value changes each time it's referenced.
s = rand('state') returns a 35-element vector containing the current state of the uniform
generator.
randn:
The randn function generates arrays of random numbers whose elements are normally
distributed with mean 0, variance (sigma^2=1) , and standard deviation (sigma=1) .
Y = randn(n) returns an n-by-n matrix of random entries. An error message appears if n is not
a scalar.
s = randn('state') returns a 2-element vector containing the current state of the normal
generator. To change the state of the generator
PROCEDURE:
1. ADD VALUES IN A VECTOR:
>> sum = 0;
for i = 1:5
sum = sum+i;
end
display(sum)
OUTPUT
sum =
15
2. CHECK SUM:
>> A = [1 2 3 4 5]
OUTPUT
A=
1 2 3 4 5
>> B = sum(A)
OUTPUT
B=
15
>> sum = 0;
>> for i = 1:5
sum = sum+i;
display(sum)
end
OUTPUT
sum =
1
sum =
3
sum =
6
sum =
10
sum =
15
4. CHECK CUMSUM:
>> A = [1 2 3 4 5]
OUTPUT
A=
1 2 3 4 5
>> B = cumsum(A)
OUTPUT
B=
1 3 6 10 15
5. RANDOM:
>> B = rand(3)
OUTPUT
B=
0.4447 0.9218 0.4057
0.6154 0.7382 0.9355
0.7919 0.1763 0.9169
>> plot(B)
>> B = randn(3)
OUTPUT
B=
0.1746 -0.5883 0.1139
-0.1867 2.1832 1.0668
0.7258 -0.1364 0.0593
>> plot(B)
EXPERIMENT:4
AIM: Evaluating a given expression and rounding it to the nearest integer value using
Round, Floor, Ceil and Fix functions; Also, generating and Plots of (A) Trigonometric
Functions - sin(t),cos(t), tan(t), sec(t), cosec(t) and cot(t) for a given duration, ‘t’. (B)
Logarithmic and other Functions – log(A), log10(A), Square root of A, Real nth root of A.
THEORY:
Round
Round to nearest integer
Syntax: Y = round(X)
Description: Y = round(X) rounds the elements of X to the nearest integers. For complex X,
the imaginary and real parts are rounded independently.
Floor
Round towards minus infinity
Syntax B = floor(A)
Description B = floor(A) rounds the elements of A to the nearest integers less than or equal to
A. For complex A, the imaginary and real parts are rounded independently.
Ceil
Round toward infinity
Syntax: B = ceil(A)
Description: B = ceil(A) rounds the elements of A to the nearest integers greater than or equal
to A. For complex A, the imaginary and real parts are rounded independently.
Fix
Round towards zero
Syntax: B = fix(A)
Description: B = fix(A) rounds the elements of A toward zero, resulting in an array of
integers. For complex A, the imaginary and real parts are rounded independently.
Trigonometric Functions
The trigonometric functions are used along with their names and have the angle value as the
parameters in them. A range for the value of the parameter is defined to attain their graphical
representations.
Syntax: A = ‘trigonometric function name’(Value)
Ex. sin(30), cos(115), tan(-45)
PROCEDURE:
1. Evaluate given expression and round it to the nearest integer value using
1. ROUND
>>round(3.67)
OUTPUT
ans =
4
2. FLOOR
>>floor(3.67)
OUTPUT
ans =
3
3. CEIL
>>ceil(3.67)
OUTPUT
ans =
4
4. FIX
>>fix(a)
ans =
1 2 9 8
TRIGONOMETRIC FUNCTIONS
1. sin(t)
>> x=(0:0.01:2*pi);
>> y=sin(x);
>>plot(x,y);
OUTPUT
2. cos(t)
>> x=(0:0.01:2*pi);
>> y=cos(x);
>>plot(x,y);
OUTPUT
3. cosec(t)
>> x=(0:0.01:2*pi);
>> y=csc(x);
Warning: Divide by zero.
> In csc at 14
>>plot(x,y);
OUTPUT
4. sec(t)
>> x=(0:0.01:2*pi);
>> y=sec (x);
>>plot(x,y);
OUTPUT
5. tan(t)
>> x=(0:0.01:2*pi);
>> y=sin(x);
>>plot(x,y);
OUTPUT
6. cot(t)
>> x=(0:0.01:2*pi);
>> y=cot(x);
Warning: Divide by zero.
> In cot at 14
>>plot(x,y);
OUTPUT
3. LOGARITHMIC FUNCTIONS
1 log(t)
>> x=(0:0.01:20)
>> plot(log(x))
Warning: Log of zero
OUTPUT
2. log10(t)
>> x=(0.01:0.01:20)
>> plot(log(x))
OUTPUT
EXPERIMENT:5
AIM: Creating a vector X with elements, Xn = (-1)n+1/(2n-1) and Adding up 100 elements
of the vector, X; And, plotting the functions, x, x3, ex, exp(x2) over the interval 0 < x < 4 (by
choosing appropriate mesh values for x to obtain smooth curves), on A Rectangular Plot
THEORY:
MATLAB PROGRAM:-
6. x 18.
7. 19.
8. plot(x(1,1:4))
20. Exp(n2)
9.
21.
10. x3
22. c=exp(x.^2);
11. a=x.^3; 23. plot(c(1,1:4))
24.
27. 0.7829
28.
29.
30. FIGURES
31.
32.
33. CONCLUSION:-
34. The given experiment has been performed successfully.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45. EXPERIMENT:6
46.
47. AIM: Generating a Sinusoidal Signal of a given frequency (say, 100Hz) and Plotting with
Graphical Enhancements - Titling, Labeling, Adding Text, Adding Legends, Adding New
Plots to Existing Plot, Printing Text in Greek Letters, Plotting as Multiple and Subplot.
48.
49. TOOL USED: MATLAB 7.0
50.
51. THEORY:
52.
53. The sin function operates element-wise on arrays. The function's domains and ranges
include complex values. All angles are in radians.
54. Y = sin(X) returns the circular sine of the elements of X.
55. MATLAB allows you to add title, labels along the x-axis and y-axis, grid lines and also to
adjust the axes to spruce up the graph.
1. The xlabel and ylabel commands generate labels along x-axis and y-axis.
3. The grid on command allows you to put the grid lines on the graph.
4. The axis equal command allows generating the plot with the same scale factors and
the spaces on both
5. axes.
76.
77. Setting Axis Scales
78. The axis command allows you to set the axis scales. You can provide minimum and
maximum values for x and y axes using the axis command in the following way:
80.
82. When you create an array of plots in the same figure, each of these plots is called a
subplot. Thesubplot command is for creating subplots.
84. subplot(m, n, p)
85. where, m and n are the number of rows and columns of the plot array and p specifies
where to put a particular plot.
86.
87.
88.
89.
123. CONCLUSION:-
124. The given experiment has been performed successfully.
125. EXPERIMENT:7
126.
127. AIM: Solving First, Second and third Order Ordinary Differential Equation using
Built-in Functions and plot.
128. TOOL USED: MATLAB 7.0
129.
130. THEORY:
131.
132. An ordinary differential equation or ODE is an equation containing a function of
one independent variable and its derivatives. The term "ordinary" is used in contrast with
the term partial differential equation which may be with respect to more than one
independent variable.
133.
134. dsolve
135.
136. Ordinary differential equation and system solver
137.
138. S = dsolve(eqn) solves the ordinary differential equation eqn. Here eqn is a symbolic
equation containing diff to indicate derivatives. Alternatively, you can use a string with
the letter D indicating derivatives. For example, syms y(x); dsolve(diff(y) == y +
1) anddsolve('Dy = y + 1','x') both solve the equation dy/dx = y + 1 with respect to the
variable x. Also, eqn can be an array of such equations or strings.
139.
140. S = dsolve(eqn,cond) solves the ordinary differential equation eqn with the initial or
boundary condition cond.
141.
142. Solving
143. Use dsolve to compute symbolic solutions to ordinary differential equations. You can
specify the equations as symbolic expressions containing diff or as strings with the
letter D to indicate differentiation.
144.
145. Before using dsolve, create the symbolic function for which you want to solve an
ordinary differential equation. Use sym or syms to create a symbolic function. For
example, create a function y(x):
146. syms y(x)
147.
148. To specify initial or boundary conditions, use additional equations. If you do not
specify initial or boundary conditions, the solutions will contain integration constants,
such as C1, C2, and so on.
149. The output from dsolve parallels the output from solve. That is, you can:
Call dsolve with the number of output variables equal to the number of dependent
variables.
Place the output in a structure whose fields contain the solutions of the differential
equations.
150.
151.
152.
153. PROCEDURE:
154.
155.
156. >> y = dsolve('Dy = y*x','x');
157. >> y = dsolve('Dy = y*x','y(1) = 1','x');
158. >> x = linspace(0,1,20);
159. >> z = eval(vectorize(y));
160. >> plot(x,z);
161.
162.
163. Output:
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175. >> eq1 = 'D2y + 8*Dy + 2*y = cos(x)';
176. >> inits2 = 'y(0)=0, Dy(0)=1';
177. >> y = dsolve(eq1,inits2,'x');
178. >> x = linspace(0,1,20);
179. >> z = eval(vectorize(y));
180. >> plot(x,z);
181.
182.
183. Output:
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202. >> eq1 = 'D3y + 3*D2y + Dy = cos(x)';
203. >> inits2 = 'y(0)=0, Dy(0)=1,D2y(0)=3';
204. >> y = dsolve(eq1,inits2,'x');
205. >> x = linspace(0,1,20);
206. >> z = eval(vectorize(y));
207. >> plot(x,z);
208.
209.
210. Output:
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232. EXPERIMENT:8
233.
234. AIM: Writing brief Scripts starting each Script with a request for input (using input)
to Evaluate the function h(T) using if-else statement, where, h(T) = (T – 10) for 0 < T <
100 = (0.45 T + 900) for T > 100. Exercise: Testing the Scripts written using A). T = 5, h
= -5 and B). T = 110, h =949.5
235.
236. TOOL USED: MATLAB 7.0
237.
238. THEORY:
239.
240. Input Funtion:
241. x = input (prompt) displays the text in prompt and waits for the user to input a
value and press the Return key. The user can enter expressions, like pi/4 or rand(3),
and can use variables in the workspace.
If the user presses the Return key without entering anything, then input returns an
empty matrix.
If the user enters an invalid expression at the prompt, then MATLAB® displays the
relevant error message, and then redisplays the prompt.
242. Example:
243. str = input(prompt,'s') returns the entered text as a string, without evaluating the
input as an expression.
244.
277.
278.
282. 294. T=
283. T= 295.
285. 5 297.
286. 298.
287. 299. h=
288. h= 300.
290. -5 302.
304.
305.
306. CONCLUSION:-
307. The given experiment has been performed successfully.
308.
309. EXPERIMENT:9
310.
311. AIM: Generating a Square Wave from sum of Sine Waves of certain Amplitude and
Frequencies.
312.
313. TOOL USED: MATLAB 7.0
314.
315. THEORY:
316.
317. hold on method:
318. ‘hold on’ retains plots in the current axes so that new plots added to the axes do not
delete existing plots. New plots use the next colors and line styles
based on the ColorOrder and LineStyleOrder properties of the axes. MATLAB® adjusts
axes limits, tick marks, and tick labels to display the full range of data.
319.
320.
323.
353. 359.
354. 360.
355. 361.
356. 362.
364.
365.
366. EXPERIMENT:10
367.
368. AIM: Generating a Square Wave from sum of Sine Waves of certain Amplitude and
Frequencies. Basic 2D and 3D plots: a) parametric space curve. b) polygons with vertices. c)
3D contour lines, pie and bar charts
369.
370. TOOL USED: MATLAB 7.0
371.
372. THEORY:
373.
374. Contour Plots
375.
376. A contour plot displays isolines of matrix Z. Label the contour lines using clabel.
377.
378. contour(X,Y,Z), contour(X,Y,Z,n), and contour(X,Y,Z,v) draw contour plots
of Z using X and Y to determine the x and y values.
If X and Y are vectors, then length(X) must equal size(Z,2) and length(Y) must
equal size(Z,1). The vectors must be strictly increasing or strictly decreasing and cannot
contain any repeated values.
If X and Y are matrices, then their sizes must equal the size of Z. Typically, you should
set X and Y so that the columns are strictly increasing or strictly decreasing and the rows
are uniform (or the rows are strictly increasing or strictly decreasing and the columns are
uniform).
379. If X or Y is irregularly spaced, then contour calculates contours using a regularly spaced
contour grid, and then transforms the data to X or Y.
380.
381. contour3 creates a 3-D contour plot of a surface defined on a rectangular grid.
382.
383. contour3(X,Y,Z), contour3(X,Y,Z,n), and contour3(X,Y,Z,v) draw contour plots
of Z using X and Y to determine the x and y values.
If X and Y are vectors, then length(X) must equal size(Z,2) and length(Y) must
equal size(Z,1). The vectors must be strictly increasing or strictly decreasing and cannot
contain any repeated values.
If X and Y are matrices, then their sizes must equal the size of Z. Typically, you should
set X and Y so that the columns are strictly increasing or strictly decreasing and the rows
are uniform (or the rows are strictly increasing or strictly decreasing and the columns are
uniform).
384. If X or Y is irregularly spaced, then contour3 calculates contours using a regularly spaced
contour grid, and then transforms the data to X or Y.
385.
386. Bar Graph Plot
387.
388. bar(y) creates a bar graph with one bar for each element in y. If y is a matrix,
then bar groups the bars according to the rows in y.
389.
390. bar3 draws a three-dimensional bar graph.
391.
392. bar3(Y) draws a three-dimensional bar chart, where each element in Y corresponds to
one bar. When Y is a vector, the x-axis scale ranges from 1 to length(Y). When Y is a matrix,
the x-axis scale ranges from 1 to size(Y,1) and the elements in each row are grouped together.
393.
394. Pie Chart Plot
395.
396. pie(X) draws a pie chart using the data in X. Each slice of the pie chart represents an
element in X.
If sum(X) ≤ 1, then the values in X directly specify the areas of the pie slices. pie draws
only a partial pie if sum(X) < 1.
If sum(X) > 1, then pie normalizes the values by X/sum(X) to determine the area of each
slice of the pie.
If X is of data type categorical, the slices correspond to categories. The area of each slice
is the number of elements in the category divided by the number of elements in X.
397.
398. pie3(X) draws a three-dimensional pie chart using the data in X. Each element in X is
represented as a slice in the pie chart.
If sum(X) ≤ 1, then the values in X directly specify the area of the pie slices. pie3 draws
only a partial pie ifsum(X) < 1.
If the sum of the elements in X is greater than one, then pie3 normalizes the values
by X/sum(X) to determine the area of each slice of the pie.
399.
400. Sphere Plot
401.
402. The sphere function generates the x-, y-, and z-coordinates of a unit sphere for use
with surf and mesh.
403. sphere generates a sphere consisting of 20-by-20 faces.
404. sphere(n) draws a surf plot of an n-by-n sphere in the current figure.
405. [X,Y,Z] = sphere(n) returns the coordinates of a sphere in three matrices that are (n+1)-
by-(n+1) in size. You draw the sphere with surf(X,Y,Z) or mesh(X,Y,Z).
406.
407.
408. Line Plots
409.
410. The plot3 function displays a three-dimensional plot of a set of data points.
411.
412. plot3(X1,Y1,Z1,...), where X1, Y1, Z1 are vectors or matrices, plots one or more lines in
three-dimensional space through the points whose coordinates are the elements of X1, Y1,
and Z1.
413.
414. Polygon Plots
415.
416. The fill function creates colored polygons.
417.
418. fill(X,Y,C) creates filled polygons from the data in X and Y with vertex color specified
by C. C is a vector or matrix used as an index into the colormap. If C is a row
vector, length(C) must equal size(X,2) and size(Y,2); if C is a column vector, length(C) must
equal size(X,1) and size(Y,1). If necessary, fill closes the polygon by connecting the last
vertex to the first.
419.
420. The fill3 function creates flat-shaded and Gouraud-shaded polygons.
421.
422. fill3(X,Y,Z,C) fills three-dimensional polygons. X, Y, and Z triplets specify the polygon
vertices. If X, Y, or Z is a matrix, fill3 creates n polygons, where n is the number of columns
in the matrix. fill3 closes the polygons by connecting the last vertex to the first when
necessary.
423.
424. Cylinder Plot
425.
426. cylinder generates x-, y-, and z-coordinates of a unit cylinder. You can draw the
cylindrical object using surf ormesh, or draw it immediately by not providing output
arguments.
427. [X,Y,Z] = cylinder returns the x-, y-, and z-coordinates of a cylinder with a radius equal
to 1. The cylinder has 20 equally spaced points around its circumference.
428.
429. PROCEDURE:
430.