Docsity

Matlab Project - Vector, Exercises of Matlab skills

Toggle sidebar
bg1
Table of Contents
Header ............................................................................................................................................... 1
Problem 1. ......................................................................................................................................... 1
Problem 2. ......................................................................................................................................... 3
Problem 3. ......................................................................................................................................... 3
Header
%Name: Dev Patel
%UID: 118602769
%Matlab Project 1 - Math241 (Mellet)
Problem 1.
fprintf("<strong>Problem 1</strong>\n\n");
%Part A
fprintf("Problem 1 - Part A\n");
format short
d = [1, -3 ,5];
norm = sqrt((1^2)+((-3)^2)+(5^2));
u = d/norm;
disp('Unit Vector:');
disp(u);
%Part B
fprintf("Problem 1 - Part B\n");
P0 = [1, 0, 2];
P1 = [2, 1, 2];
P2 = [1, 3, 0];
V1 = P1-P0;
V2 = P2-P0;
N = cross(V1, V2);
disp('Normal Vector:');
disp (N);
%Part C
fprintf("Problem 1 - Part C\n");
P = [1, 2, 3];
P1 = [1, 4, 7];
P2 = [-1, 3, 6];
U = P2-P1;
V = P-P1;
D1 = dot(V, U);
D2 = dot(U, U);
K = (D1/D2);
Q = P1 + U*K;
PQ = Q-P;
1
pf3
pf4
pf5

Partial preview of the text

Download Matlab Project - Vector and more Exercises Matlab skills in PDF only on Docsity!

Table of Contents

Header ............................................................................................................................................... 1 Problem 1. ......................................................................................................................................... 1 Problem 2. ......................................................................................................................................... 3 Problem 3. ......................................................................................................................................... 3

Header

%Name: Dev Patel %UID: 118602769 %Matlab Project 1 - Math241 (Mellet)

Problem 1.

fprintf("Problem 1\n\n");

%Part A fprintf("Problem 1 - Part A\n"); format short d = [1, -3 ,5]; norm = sqrt((1^2)+((-3)^2)+(5^2)); u = d/norm; disp('Unit Vector:'); disp(u);

%Part B fprintf("Problem 1 - Part B\n"); P0 = [1, 0, 2]; P1 = [2, 1, 2]; P2 = [1, 3, 0]; V1 = P1-P0; V2 = P2-P0; N = cross(V1, V2); disp('Normal Vector:'); disp (N);

%Part C fprintf("Problem 1 - Part C\n"); P = [1, 2, 3]; P1 = [1, 4, 7]; P2 = [-1, 3, 6]; U = P2-P1; V = P-P1; D1 = dot(V, U); D2 = dot(U, U); K = (D1/D2); Q = P1 + U*K; PQ = Q-P;

distance = sqrt((2^2)+(1^2)+(3^2)); disp('Distance from point to line:'); disp (distance);

%Part D fprintf("Problem 1 - Part D\n"); A = [4,5,3]; B = [2,3,-2]; N = cross(A, B); M = sqrt((19^2)+(14^2)+(2^2)); V = (N/M); P = [0,-2,-1]; D = dot(N, P); Equation = [N, D]; disp('Equation of the plane:'); fprintf(' %dx + %dy + %dz = %d\n\n', Equation);

%Part E fprintf("Problem 1 - Part E\n"); A = [3, 1, 0]; B = [1, 2, 3]; C = [0, -1, -2]; AB = B-A; AC = C-A; BC = C-B; LAB = sqrt((2^2)+(1^2)+(3^2)); LAC = sqrt((3^2)+(2^2)+(2^2)); LBC = sqrt((1^2)+(3^2)+(5^2)); V = LAB + LAC + LBC; S = (V/2); Area = sqrt((S(S-(LAB))(S-(LAC))*(S-(LBC)))); disp('Area of the triangle:'); disp(Area);

Problem 1

Problem 1 - Part A Unit Vector: 0.1690 -0.5071 0.

Problem 1 - Part B Normal Vector: -2 2 3

Problem 1 - Part C Distance from point to line: 3.

Problem 1 - Part D Equation of the plane: -19x + 14y + 2z = -

Problem 1 - Part E Area of the triangle:

hold on; ezplot3(x, y, z, [0, 4*pi]); title('Parametric Curve: r(t)'); xlabel('X'); ylabel('Y'); zlabel('Z');

%Part B P = [2, 0, 3]; Q = [3, -2, 1]; QP = Q - P; syms t; line = P + QPt; fprintf('The line [x(t), y(t), z(t)] passing through points P and Q is '); disp(line); figure; ezplot3(line(1), line(2), line(3),[0,4pi]) hold on plot3(2, 0, 3, 'o') plot3(3, -2, 1, 'o') quiver3(2,0,3,1,-2,-2); xlabel('X'); ylabel('Y'); zlabel('Z'); title('Line Passing Through Points P and Q'); hold off

Problem 3

The line [x(t), y(t), z(t)] passing through points P and Q is [t + 2, -2*t, 3

- 2*t]