Cosine function does not work

4 ビュー (過去 30 日間)
Szymon Wlodarczyk
Szymon Wlodarczyk 2016 年 5 月 10 日
回答済み: mustafa ün 2019 年 1 月 18 日
I have recently faced a silly problem using cosine (Y=cos(x)). I am trying to compute:
cos(ksi1)
where ksi1 equals to 2.8322 and is type double. I am getting only an error:
"Subscript indices must either be real positive integers or logicals."
What is funny that sin(ksi1) returns a value, 0.3044. Moreover, I can compute value cos(ksi1) using Pythagorean trigonometric identity.
It just eats my nerves. I am working with MATLAB R2013a.

採用された回答

James Tursa
James Tursa 2016 年 5 月 10 日
編集済み: James Tursa 2016 年 5 月 10 日
You have inadvertently created a variable with the name "cos" that is shadowing the function "cos". Clear the variable, and pick a different variable name to use for the calculation you are doing to avoid the same problem in the future. E.g.,
>> which cos
built-in (C:\Program Files\MATLAB\R2015a\toolbox\matlab\elfun\@double\cos) % double method
>> cos(2.8322)
ans =
-0.9525
>> cos = 4 % <-- creating a variable named cos
cos =
4
>> which cos
cos is a variable.
>> cos(2.8322)
Subscript indices must either be real positive integers or logicals.
>> clear cos
>> cos(2.8322)
ans =
-0.9525
  1 件のコメント
Szymon Wlodarczyk
Szymon Wlodarczyk 2016 年 5 月 10 日
That was the problem. Thank you.

サインインしてコメントする。

その他の回答 (1 件)

mustafa ün
mustafa ün 2019 年 1 月 18 日
execllent fro beginners

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by