How can I do this iteration?
3 次查看(过去 30 天)
显示 更早的评论
Hi, I have a simple question related to a problem.
I have to make an iterative code which updates values of some hypothesized vectors, until I reach convergence.
To simplify, I have two vectors a,b with initial assumed values, then the cycle updates their values until it stops when:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/680163/image.png)
I think this can be solved with an easy code, maybe with a while cicle?
Thank you for your help!
0 个评论
回答(1 个)
ANKUR KUMAR
2021-7-11
编辑:ANKUR KUMAR
2021-7-11
Here is the sample code using random data
a=rand(1,50);
b=rand(1,50);
threshold=0.5; % You need to change it to 1e-6 and use original data
i=1;
out= -9999; % setting random data
while out<threshold
out(i)=abs(a(i+1)-a(i))+abs(b(i+1)-b(i));
i=i+1;
end
out
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!