use a Loop to repeat an equation using the previous answer as the new variable.
19 views (last 30 days)
Show older comments
Adam Kevin Francis Baker
on 4 May 2019
Commented: Adam Kevin Francis Baker
on 4 May 2019
I want to write a loop to do the below all the way up to p340....I do not want to change the name of the variable each time but instead would like all variables in one array. I have been searching and trying to figure this out for hours. I've written so many different forms of a for loop I don't know what to include here.
xt = 100:440
p1 = 99977
p2 = p1./(exp((50)./(29.3.*((xt)))))
p3 = p2./(exp((50)./(29.3.*((xt)))))
p4 = p3./(exp((50)./(29.3.*((xt)))))
....etc
4 Comments
Accepted Answer
KALYAN ACHARJYA
on 4 May 2019
Edited: KALYAN ACHARJYA
on 4 May 2019
xt=100:440;
p={};
p{1}=99977;
for i=2:340;
p_iter=p{i-1};
deno=exp(50./(29.3*(xt)));
p{i}=p_iter./deno;
end
3 Comments
Stephen23
on 4 May 2019
Edited: Stephen23
on 4 May 2019
".the first value of the array in that cell is the correct value for that iteration.."
That is quite interesting, because the first values of each vector corresponds to the first value of the xt vector. So effectively you want to ignore all of the other xt values. Is this correct?
EDIT: you have now accepted KALYAN ACHARJYA's complex answer, which according to your own comment does not do what you want. You wrote: ".the first value of the array in that cell is the correct value for that iteration" and now you have shown in your own comment (by the addition of xt(i) indexing) that what you described is not what you want at all.
Simpler answer:
More Answers (0)
See Also
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!