フィルターのクリア

I am confused on why I am getting huge numbers at the values 0,75,150, and 300 in my code

3 ビュー (過去 30 日間)
For some reason, I am getting huge numbers in c for x= 0, 75, 150, and 300. Which is obviously not correct. I am not sure what is wrong. Here is my code:
x = [0:300];
lda = 300; % in km
k = ((2*pi)/(lda));
a = (cos(k*x));
b = (cos((k*x)-(pi/2)));
c = (a)./(b);
plot(x, c)

採用された回答

Walter Roberson
Walter Roberson 2023 年 9 月 26 日
Algebraically, b should be 0 at 0, 150, 300 (but not 75), and division by 0 gives infinity. In the below plot, you do not see the infinity because they are only single points and plot() automatically clips out infinite values.
Now, I said "Algebarically". But you are using finite double precision representations and the calculated values are not exact multiples of and numeric cos(pi/2) does not give exactly 1 because of finite precision reasons.
How can you avoid the problem? Well, you can use symbolic calculations.. or you could rewrite a little and use sinpi and cospi
Pi = sym(pi);
x = [0:300];
lda = 300; % in km
k = ((2*Pi)/(lda));
a = (cos(k*x));
b = (cos((k*x)-(Pi/2)));
c = (a)./(b);
plot(x, c)
temp = [a;b;c];
mask = ismember(x, [0, 75, 150, 300]);
temp(:,mask)
ans = 

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by