How can I update initial value of an array in a for loop?
Show older comments
a(1)=0.1, a(2)= 0.11;
for k=2:10^10
a(k+1)= a(k)+a(k-1)+.....
if a(k+1)> 5.0
Up = k ;
end
end.
It takes a lot of memory as iteration number is very high.
How can I update the initial value like a(3)=a(2); a(1)=a(2)
and find new a(3) till my condition is satisfied.
6 Comments
Greg
on 10 Feb 2018
Do a little research on preallocation.
Greg
on 10 Feb 2018
What is the purpose of
count = count + 1;
suman Dhamala
on 10 Feb 2018
suman Dhamala
on 10 Feb 2018
Greg
on 10 Feb 2018
My comment on preallocation comes from the ambiguity of a(k+1)= a(k)+a(k-1)+..... This made me think you needed the entire vector.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!