Java Scrap Book  

Java Scrap Book > MATLAB > Vectors

Vectors

function lab2
M=[.1,-.2,-.1];
N=[-.2,.1,.3];
P=[.4,0,.1];
Rnm=M-N;
Rpm=M-P;
magRnm=norm(Rnm);
magRpm=norm(Rpm);
disp('Resultant Rnm');
sprintf('Magnitude: %f',magRnm)
sprintf('(%fax %fay %faz)',Rnm(1),Rnm(2),Rnm(3))

d=dot(Rnm,Rpm);
disp('Dot product:');
disp(d);

project=(dot(Rnm,Rpm)/dot(Rpm,Rpm))*Rpm;
disp('Projection: ');
sprintf('(%fax %fay %faz)',project(1),project(2),project(3))

cos_theta=(dot(Rnm,Rpm)/(magRpm*magRnm));
theta=acos(cos_theta);
disp('The angle is: ');
disp(theta);
end


Copyright © 2013-2018

javascrapbook.com is a computer science content service should not be treated as the publisher or speaker of any information provided by another Computer Science content provider.

Contact email: help@javascrapbook.com