if
input_x={1/6,1/6,1/6,1/6,1/6,1/6}
How can I generate this function:
i=1:6
pi_all(i)=(1-(i-1)/5)*(0.45+1.1*(input_x(i)/2 +sum(input_x(i:i-1))))

댓글 수: 6

Walter Roberson
Walter Roberson 2018년 1월 5일
Are you looking for a way to vectorize the expression?
Note that i:i-1 is empty in MATLAB.
Torsten
Torsten 2018년 1월 5일
In sum(...), you refer to input_x(1:0). But input_x(0) does not exist in MATLAB language.
Best wishes
Torsten.
pervesh anthwal
pervesh anthwal 2018년 1월 5일
then how can I write summation input_x(j) for j<i for this equation
Which elements of input_x do you want to sum if you write
sum(input_x(i:i-1))
?
Best wishes
Torsten.
Walter Roberson
Walter Roberson 2018년 1월 5일
Torsten:
1:0 is not the same as [1, 0]. 1:0 is empty, so input_x(1:0) is the empty vector.
Why are you not using a loop and
sum(input_x(1:i-1))

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

답변 (1개)

pervesh anthwal
pervesh anthwal 2018년 1월 6일
편집: Walter Roberson 2018년 1월 6일

0 개 추천

what I want to do is:
for i=1
pi_all(i)=(1-(1-1)/5)*(0.45+1.1*(input_x(1)/2))
In this expression I want sum term to be 0 as i!=0
for i=2
pi_all(2)=(1-(2-1)/5)*(0.45+1.1*(input_x(2)/2 +sum(input_x(2:2-1))))
In here sum will take only input_x(1)
for i=3
pi_all(i)=(1-(3-1)/5)*(0.45+1.1*(input_x(3)/2 +sum(input_x(3:3-1))))
In here sum will take input_x(1)+input_x(2)
and so on.

댓글 수: 1

If you are using a loop, then like I indicated,
sum(input_x(1:i-1))

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

카테고리

도움말 센터File Exchange에서 Instrument Control Toolbox에 대해 자세히 알아보기

질문:

2018년 1월 5일

댓글:

2018년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by