How do I avoid using for loops in the following problem?

B=[b1,b2,..,bn], C=[c1,c2,...,cn] , and D=[d1,d2,...,dn]|are known. A scalar |A(0) is also known. I need to calculate A(1)...A(n) using the following iteration: A(i)=max{ci,A(i-1)+bi}+di,i=1,...,n. Is there any method or function I can use to get A(1)...A(n) without using a for loop? Thank you in advance!

回答 (1 件)

埃博拉酱
埃博拉酱 2024 年 10 月 28 日

0 投票

迭代类问题通常都不能向量化,因为循环之间存在依赖关系。

カテゴリ

ヘルプ センター および File Exchange循环及条件语句 についてさらに検索

質問済み:

2018 年 3 月 22 日

回答済み:

2024 年 10 月 28 日

Community Treasure Hunt

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

Start Hunting!