My code is returning a complex array

조회 수: 1 (최근 30일)
Cameron
Cameron 2022년 11월 3일
댓글: Torsten 2022년 11월 3일
x = -10:1:10;
for j = -10:1:10
y(j+11) = power(2.72,-.2j);
end
plot(x,y);
%im trying to plot the function e^(-.2x) so im trying to create an array to plot
  댓글 수: 1
Torsten
Torsten 2022년 11월 3일
-.2j means -0.2*i where i is the imaginary unit (sqrt(-1)).

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2022년 11월 3일
편집: KSSV 2022년 11월 3일
There is a typo in your code.
x = -10:1:10 ;
y = zeros(size(x)) ;
for j = 1:length(x)
y(j) = power(2.72,-0.2*j); %<---missed mulltiplication
end
plot(x,y);
No need to use loop.
x = -10:1:10;
y = exp(-0.2*x) ;
plot(x,y)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by