User talk:Eml4500.f08.team.Bengtson

Homework 1
Graphics Hardcopy

In MATLAB, there is often a need to obtain a copy of the graphic produced. The ‘Print’ option is what is used to do this. By itself this sends a high resolution copy directly to an attached printer. Adding commands such as a filename afterwards writes the current graphic to a file.

Print Eml4500

Writes current graphic to file Eml4500.

However, if the filename already exists then it will be overwritten. To attach several graphics to one file ‘-append’ should be put after the print command and before the filename that is being added to.

Print -append Eml4500

Adds current figure to eml4500 file.

Also, if one wants to get a figure besides the current one to print one just uses –fN with the print command with N being the number of the figure one wishes to write.

Print -f2 Eml4500

Prints the figure 2 to eml4500 file.

3-D Line Plots

A 3-D line plot can be with the plot3(x,y,z) command. This means that x, y, and z already have to be defined which usually is done parametrically.

T=.01:.01:20*pi; x=cos(t); y=sin(t); z=t.^3; plot3(x,y,z)

This would show a helix that compresses toward the x-y plan. To add a label to the z-axis there is a command ‘zlabel’. As well as the axis command can be used to set the scaling to prescribed limits.

3-D mesh and surface plots

There a couple commands to create mesh and surface plots. ‘Mesh(z)’ creates a three-dimensional perspective plot of the elements of matrix z. The mesh surfaced is defined by the z-coordinates above the x-y plane. Surface plots are plotted with the command ‘surf(z)’, where z is a matrix. To draw a mesh within a set of perimeter one can define a rectangle with the xx and yy vectors	 [x,y] = meshgrid(xx,yy) where [x,y] is defined through ‘z=’

xx=-3:.3:3;

yy=xx;

[x,y] = meshgrid(xx,yy);

z = exp(-x.^2 - y.^2);

mesh(z);

To impose shading on the plots and grids there is three options: shading faceted, shading interp, and shading flat. This command should be entered after the surf command. There are several predefined color profiles to choose from. To change it, use the command ‘colormap(hsv)’ which is default color profile to another selection such as ‘colormap(hot)’. The different predefined color values are hsv, hot, cool, jet, pink, copper, flag, gray, and bone.

The command ‘view’ can be used to specify from what location in coordinates the 3D object should be viewed from. It can be in either cartesian or spherical coordinates.

Sparse Matrix Calculations

MATLAB when performing matrix calculations by default assumes that any of the entries may be nonzero. However, sometimes this is not the case and to avoid lengthy calculations that become zero, there is a way to increase the efficiency so the processing power can find solutions to significantly larger problems.

The commands ‘full’ or ‘sparse’ change between the two settings, where a sparse matrix is stored as a linear array of the nonzero entries along with their row and column numbers. A full matrix records every single entry.

The sparse equivalents of eye, ones, and randn are simply done by adding sp before the command, for example ‘sprandn’. The command ‘sparse(m,n)’ creates a sparse zero matrix.

The sparse command can also create a sparse matrix by listing its nonzero components.

An example,

i = [1 2 3 4 4 4]; j = [1 2 3 1 2 3]; s = [5 6 7 8 9 10]

S= sparse(i, j, s, 4, 3);

The nonzero entries come from ‘s’ and their location by row and column number is i and j respectively. The matrix size is given by the last two numbers which makes it an m x n matrix or in this case 4x3.

Most of MATLAB operations can be used regardless of storage mode (either full or sparse). Most operation just involving a sparse matrix will continue to be in sparse mode such as S*S, S+S, inv(S), or S^n, while certain ones will be recorded in full mode such as S+F, S*F, S/F or F/S.