matlab acos
时间: 2023-10-21 19:06:07 浏览: 46
The function acos(x) in MATLAB computes the inverse cosine (arc cosine) of x, where x is a scalar or an array of real numbers in the interval [-1, 1]. The result of the function is a scalar or an array of the same size as x, containing the angles in radians whose cosine is x.
Syntax:
y = acos(x)
Examples:
1. Compute the inverse cosine of a scalar:
x = 0.5;
y = acos(x); % y = pi/3 = 1.0472
2. Compute the inverse cosine of an array:
x = [-1, 0, 0.5, 1];
y = acos(x); % y = [pi, pi/2, 1.0472, 0]
Note that the inverse cosine of -1 is pi, which is the angle in radians that corresponds to a cosine of -1 (i.e., 180 degrees).
3. Use the inverse cosine to compute the angle between two vectors:
a = [1, 2, 3];
b = [4, 5, 6];
cos_theta = dot(a, b) / (norm(a) * norm(b)); % compute the cosine of the angle between a and b
theta = acos(cos_theta); % compute the angle in radians
theta_deg = rad2deg(theta); % convert the angle to degrees
% theta = 0.2257 radians or 12.931 degrees