필터 지우기
필터 지우기

index must b positive?plz help

조회 수: 2 (최근 30일)
khushi
khushi 2015년 8월 22일
답변: Walter Roberson 2015년 8월 22일
clc;clear all;
g_db=[0:1:10];
g=10.^(g_db/10);
alpha=2;
c=1;
M=2;
syms y
r=0;
for j=2:M
p=((-1)^j)*(factorial(M)/factorial(j)*factorial(M-j))*exp(-(g.*y(1-(1/j))));
r=r+p;
t=r*(1/M)
end
x=((y.^(alpha-1)).*exp(-y./c))/((gamma(alpha))*(c^alpha));
z=t*x;
semilogy(g_db,z);
hold on

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 22일
You have the expression
p=((-1)^j)*(factorial(M)/factorial(j)*factorial(M-j))*exp(-(g.*y(1-(1/j))));
The y(1-(1/j)) part of that says to index the variable y at index (1-(1/j)) . As all of your j are at least 2, 1/j is less than 1 so 1-1/j is not a positive integer.
Perhaps you wanted to code multiplication instead of indexing. y*(1-(1/j))

태그

Community Treasure Hunt

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

Start Hunting!

Translated by