필터 지우기
필터 지우기

draw a function composed of sin and cos

조회 수: 1 (최근 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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by