In: Physics
Given ? = ???+??? + ??? and ? = ???-3?? + ????. Use MATLAB to find the following: a) ? + ? b) ? ? c) ? × ? d) A unit vector in the direction of ? − 2? e) ??? f) The component of ? along ?
2. Use MATLAB to convert points ?(11,4,15), ?(10,−14,33) and ?(−33,−14,15) from Cartesian to Cylindrical and Spherical coordinates.
(1)
Code:
A = [5, 7, 2];
B = [2, -3, 22];
C = A + B;
D = A-B;
E = cross(A, B);
F = A-2*B;
F = F/norm(F);
theta = acos(dot(A, B)/norm(A)/norm(B));
component = dot(A,B)/norm(B)^2 *B;
sprintf('A+B = %f ax + %f ay + %f az',C(1), C(2), C(3))
sprintf('A-B = %f ax + %f ay + %f az',D(1), D(2), D(3))
sprintf('AxB = %f ax + %f ay + %f az',E(1), E(2), E(3))
sprintf('unit vector in direction of A-2B = %f ax + %f ay + %f
az',F(1), F(2), F(3))
sprintf('theta = %f rad',theta)
sprintf('component of A along B = %f ax + %f ay + %f
az',component(1), component(2), component(3))
Output:
>> d
ans = A+B = 7.000000 ax + 4.000000 ay + 24.000000 az
ans = A-B = 3.000000 ax + 10.000000 ay + -20.000000 az
ans = AxB = 160.000000 ax + -106.000000 ay + -29.000000 az
ans = unit vector in direction of A-2B = 0.022739 ax + 0.295607 ay
+ -0.955039 az
ans = theta = 1.402396 rad
ans = component of A along B = 0.132797 ax + -0.199195 ay +
1.460765 az
(2)
Write two functions spherical and cylindrical to convert:
Spherical:
function f = spherical(x, y, z)
r = norm([x, y, z]);
theta = acos(z/r);
phi = atan(y/x);
f=[r, theta, phi];
end
Cylindrical:
function f = cylindrical(x, y, z)
r = norm([x, y]);
phi = atan(y/x);
f=[r, phi, z];
end
Now call these two functions to convert the three points:
Output:
>> spherical(11,4,15)
ans =
19.02630 0.66262 0.34877
>> cylindrical(11,4,15)
ans =
11.70470 0.34877 15.00000
>> spherical(10,-14,33)
ans =
37.21559 0.48058 -0.95055
>> cylindrical(10,-14,33)
ans =
17.20465 -0.95055 33.00000
>> spherical(-33,-14,15)
ans =
38.85872 1.17449 0.40123
>> cylindrical(-33,-14,15)
ans =
35.84690 0.40123 15.00000
>>