How to Generate this Function?
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 5 Jan 2018
Are you looking for a way to vectorize the expression?
Note that i:i-1 is empty in MATLAB.
Torsten
le 5 Jan 2018
In sum(...), you refer to input_x(1:0). But input_x(0) does not exist in MATLAB language.
Best wishes
Torsten.
pervesh anthwal
le 5 Jan 2018
Torsten
le 5 Jan 2018
Which elements of input_x do you want to sum if you write
sum(input_x(i:i-1))
?
Best wishes
Torsten.
Walter Roberson
le 5 Jan 2018
Torsten:
1:0 is not the same as [1, 0]. 1:0 is empty, so input_x(1:0) is the empty vector.
Walter Roberson
le 5 Jan 2018
Why are you not using a loop and
sum(input_x(1:i-1))
Réponses (1)
pervesh anthwal
le 6 Jan 2018
Modifié(e) : Walter Roberson
le 6 Jan 2018
1 commentaire
Walter Roberson
le 6 Jan 2018
If you are using a loop, then like I indicated,
sum(input_x(1:i-1))
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!