フィルターのクリア

draw a function composed of sin and cos

2 ビュー (過去 30 日間)
khaled Abdelghafar
khaled Abdelghafar 2022 年 2 月 26 日
コメント済み: Steven Lord 2022 年 2 月 26 日
i encounter an error when trying ti plot this function
x=-pi:0.1*pi:pi;
y1=100*sqrt(2*pi)/sqrt(0.05*pi).*cos(x/2)*(1.-cos(x/2.)*sin(x/2.)*sin(3.*x/2.));
figure
plot(x,y1)

採用された回答

Star Strider
Star Strider 2022 年 2 月 26 日
Use element-wise operations
y1=100*sqrt(2*pi)/sqrt(0.05*pi).*cos(x/2).*(1.-cos(x/2.).*sin(x/2.).*sin(3.*x/2.));
See Array vs Matrix Operations for details.
x=-pi:0.1*pi:pi;
y1=100*sqrt(2*pi)/sqrt(0.05*pi).*cos(x/2).*(1.-cos(x/2.).*sin(x/2.).*sin(3.*x/2.));
figure
plot(x,y1)
.
  1 件のコメント
Steven Lord
Steven Lord 2022 年 2 月 26 日
What @Star Strider has written is correct but one section might be slightly misleading for newer users.
% (1.-cos(x/2.).*sin(x/2.).*sin(3.*x/2.))
That first part may make you think there is an operator .- that does element-wise subtraction. But that's not the case. That period is not part of the operator but part of the number itself, since subtraction already applies element-wise. [There's also no .+ operator; just + is sufficient.]
x = 1.; % one
y = 1; % also one
x == y % true
ans = logical
1
Note that something like this would error instead.
x = 1.1 .- 1
Invalid use of operator.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by