E7_Lecture7a_Su10+posted

E7_Lecture7a_Su10+posted - Comments and blank lines add...

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

View Full Document Right Arrow Icon
E7 L6 1 Comments and blank lines add readability Comments and blank lines add readability function [dp,cp] = vecop1(v,w) % VECOP computes dot product and cross % product of two 3-dimensional vectors. dp = sum(v.*w); % compute dot product cp = zeros(3,1); % create 3-by-1 % compute cross product elements cp(1) = v(2)*w(3) – w(2)*v(3); cp(2) = v(3)*w(1) – w(3)*v(1); cp(3) = v(1)*w(2) – w(1)*v(2);
Background image of page 1

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

View Full DocumentRight Arrow Icon
E7 L6 2 Running the function vecop - Output arguments Running the function vecop - Output arguments >> v1 = [1;-2;3]; >> v2 = [0;1;1]; >> [A,B] = vecop(v1,v2) A = 1 B = -5 -1 1 >> v1 = [1;-2;3]; >> v2 = [0;1;1]; >> A = vecop(v1,v2) A = 1 >> v1 = [1;-2;3]; >> v2 = [0;1;1]; >> vecop(v1,v2) ans = 1 first output second output first output ( only ) first output ( only ) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [dp,cp] = vecop(v,w) function vecop declaration line matlab base workspace …
Background image of page 2
E7 L6 3 Calling a function – (function workspace) Calling a function – (function workspace) >> v1 = [1;-2;3];
Background image of page 3

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

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

This note was uploaded on 08/14/2010 for the course E 7 taught by Professor Patzek during the Summer '08 term at University of California, Berkeley.

Page1 / 5

E7_Lecture7a_Su10+posted - Comments and blank lines add...

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

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