Matlab:返回反余弦(acos)的完整解

时间:2014-12-01 19:12:38

标签: matlab

我有一些以下形式的Matlab代码:

syms theta x theta = acos(x)

这将返回theta的单个解决方案。但是,我想返回完整的解决方案(在某些限制之间)。

例如,

x = cos(theta)

对于θ= 60度,120度,420度等,

会给出x = 0.5。因此,在上面的代码中,我希望theta返回所有这些可能的值。

有谁知道怎么做?我一直在谷歌搜索几个小时,但我找不到如何做到这一点!

非常感谢!

2 个答案:

答案 0 :(得分:1)

这是一个数值解决方案;就像Benoit_11一样,在这种背景下,我没有看到象征性地做到这一点。

区间内有两个解决方案[-pi,pi],较大的一个由acos返回:

% solution within [0, pi]
theta1 = acos(x);
% solution within [-pi, 0]
theta2 = -acos(x);

这些解决方案以2 pi的步骤重复。向下和向上的可能步骤的数量可以由基本解决方案与相应限制(lowerupper)之间的距离的整数部分确定,以2π为单位。对于theta1

% repetitions in 2 pi intervals within limits
sd = floor((theta1 - lower) / (2 * pi));
su = floor((upper - theta1) / (2 * pi));
theta1 = (-sd : su) * 2 * pi + theta1

同样适用于theta2

% repetitions in 2 pi intervals within limits
sd = floor((theta2 - lower) / (2 * pi));
su = floor((upper - theta2) / (2 * pi));
theta2 = (-sd : su) * 2 * pi + theta2

如果您想要一个合并的解决方案列表,请排除可能的重复项:

theta = unique([theta1, theta2])

并且以度为单位:

theta = theta / pi * 180;

示例:

x = 0.5;
lower = -10;
upper = 30;

给出

theta =

   -7.3304   -5.2360   -1.0472    1.0472    5.2360    7.3304   11.5192   13.6136   17.8024   19.8968   24.0855   26.1799

答案 1 :(得分:-1)

你只需要使用一个循环:

for x = limit_inf:step:limit_sup
    theta(x) = acos(x);
end

并定义您的限制以及它们之间的步骤。

相关问题