matlab中atan2的参数不能用变量代替么

需要编一段程序,考虑到角度范围,不能用atan(),只能用atan2()。atan2()中的两个参数需要用字母表示,每次运算时候给(y,x)赋值,但是报错。
***atan可以计算数字参数:
>> y=1;
>> x=-1;
>> atan(y/x)
ans =
-0.7854
***atan2也可以计算数字参数:
>>atan2(1,-1)
ans =
2.3562
***atan可以计算字母参数:
>> syms y
>> syms x
>> atan(y/x)
ans =
atan(y/x)
***但是atan2却不能计算字幕参数么?
>> syms y
>> syms x
>> atan2(y,x)
Undefined function 'atan2' for input arguments of type 'sym'.
我看matlab的help里,例子也都是具体的数字,没有字母表示的例子。
问题出在哪里?我要想实现atan(y/x)结果那样的形式,该如何实现呢?

这个比较麻烦,因为atan2 是根据x,y的正负判断角度在第几象限
但是符号变量sym是不能判断正负的,所以atan2就没有定义sym变量作为参数时的情况

要实现atan2就要看你实际使用中的情况,是不是一定要用符号sym算符
只要你是有实在数据的就可以用数值代入的办法

x=[1 2 3 4 -5];
y=[-2 3 -4 5 6];
atan2(y,x)

ans =

-1.1071 0.9828 -0.9273 0.8961 2.2655

atan2是可以用变量的。只是不能用符号变量。
温馨提示:答案为网友推荐,仅供参考
相似回答