{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E7_Lecture7a_Su10+posted

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

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);

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

View Full Document
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 …
E7 L6 3 Calling a function – (function workspace) Calling a function – (function workspace) >> v1 = [1;-2;3]; >> v2 = [0;1;1]; >> [A,B] = vecop(v1,v2) A = 1 B = -5 -1 1 BASE WORKSPACE v1 3-by-1 v2 3-by-1 A 1-by-1 B 3-by-1 function [dp,cp] = vecop(v,w) dp = sum(v.*w); cp = zeros(3,1); cp(1) = v(2)*w(3)-w(2)*v(3); cp(2) = v(3)*w(1)-w(3)*v(1);

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}