Use while loop in equation

3 ビュー (過去 30 日間)
JORGE ORDOÑEZ CARRASCO
JORGE ORDOÑEZ CARRASCO 2020 年 12 月 9 日
I need to calculate a values c2, c3, c4,..., using the equation:
where alpha and beta are the elements of a given vectors of length k. For each q i need to calculate the result. usually Cq will result zero, so i need to find what value of q will be different to zero. I think to do that thing in matlab is using while, but my problem is combine summatory and while in matlab.
for example
in this case the value of k is 2, aplying the equation above for each c2=c3=c4=0 except in c5 which means q=5, by the way values of q start from 2 and above.
Please help me.
  4 件のコメント
David Hill
David Hill 2020 年 12 月 9 日
You should be able to easily modify my answer to match your indexing.
JORGE ORDOÑEZ CARRASCO
JORGE ORDOÑEZ CARRASCO 2020 年 12 月 9 日
I need to break the calculation when a cq is different to zero. I was thinking to use a while loop, to break the calculation when a cq is different to zero. I can use so sum((1:k) expression) inside the while I don’t know maybe can work. Thanks

サインインしてコメントする。

回答 (1 件)

David Hill
David Hill 2020 年 12 月 9 日
C=@(q)sum((1:k).^q.*alpha)/factorial(q)-sum((1:k).^(q-1).*beta)/factorial(q-1);
q=1:100;
c=arrayfun(@(x)C(x),q);
plot(q,c);
  1 件のコメント
JORGE ORDOÑEZ CARRASCO
JORGE ORDOÑEZ CARRASCO 2020 年 12 月 9 日
Nice clue

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by