Tutorial01 - City University of Hong Kong Electronic...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: City University of Hong Kong Electronic Engineering Semester B 2007-2008 EE3108 Engineering Analysis Tutorial 1 The last tutorial demonstrated the basic Matlab operations and script execution. This tutorial is a bit more advanced. It is about matrix indexing, functions, for-loops and 3-D plots. I. Matrix indexing Try the following commands and see how Matlab responds to them. Fill out the following form: Matlab Command A=[1 2 3; 4 5 6] A(1,2) A(2,1) A( : ,2) A’ x=[1:3] y=[1:3] x .*y x * y’ x’ * y Result Remarks 2×3 matrix 1st row, 2nd column 2nd row, 1st column All rows, 2nd column Transpose II. Functions Matlab allows the users to define their own functions. The steps are similar, but not the same, as running a script file. 1. Type edit to invoke the Matlab editor. 2. Type the following lines in the editor: EE 3108 Semster B 2007/2008 T1-1 S C Chan %Function: sqsum function out = sqsum(n) temp = 0; for k = 1:n temp=temp+k^2; end out = temp; 3. Create a folder in the \Desktop\EE3108\ and save the file there as sqsum.m (the same name as the function. 4. Try to run sqsum(1), sqsum(2) and sqsum(3) in the console. What are the results? III. Plots The following demonstrates 3-dimensional plotting using the mesh function. Try to run it as a script. %File: t0103 clear; % x=[-1:0.2:1]; y=[-1:0.2:1]; N=length(x); M=length(y); for n = 1:N for m = 1:M z(m,n)=x(n)^2+y(m)^2; end end mesh(x,y,z); 2 1.5 1 0.5 0 1 0.5 0 0 −0.5 −1 −1 −0.5 0.5 1 T1-2 ...
View Full Document

This note was uploaded on 01/11/2011 for the course EE 3108 taught by Professor Nelsonszechunchan during the Spring '07 term at City University of Hong Kong.

Page1 / 2

Tutorial01 - City University of Hong Kong Electronic...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online