在Matlab中向量化递归方程 [英] Vectorizing a recurrence equation in matlab
本文介绍了在Matlab中向量化递归方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个递归方程:
a(i+1)=a(i)+(((b(i)+b(i+1))*(c(i+1)-c(i)))/(d(i)+d(i+1)));
我有必需的向量b
,c
和d
,它们的长度都相同.我可以假设a(1)=0
.
I have the required vectors b
,c
, and d
and they all have the same length. I can assume that a(1)=0
.
通常,我总是使用循环来执行此操作,但是由于数据太大,因此需要花费大量时间.我想知道是否有矢量化a
的方法?
Generally, I always do this using a loop but since the data is too large, it takes a considerable amount of time. I was wondering if there is a way to vectorize a
?
推荐答案
我认为我已经找到答案了.在纸上做了一点数学后,我得到了:
I think that I have got the answer. After doing a bit of math on paper, I get this:
a=cumsum([a(1) ((b(1:end-1)+b(2:end)).*diff(c))./(d(1:end-1)+d(2:end))]);
这篇关于在Matlab中向量化递归方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文