How can I write loops in MATLAB?
古いコメントを表示
How can I write a loop to calculate the future value for each year from 1 to n? is it like a java loop here or different?
3 件のコメント
Sean de Wolski
2011 年 1 月 26 日
Can you provide a small example of the calculation you're going to use to get the future value?
Matt Fig
2011 年 1 月 26 日
This question is really vague. Please provide a small, succinct example of input data and output data.
Santosh Kasula
2011 年 1 月 26 日
Khaleel, I just made your question more descriptive.
採用された回答
その他の回答 (1 件)
Oleg Komarov
2011 年 1 月 26 日
An example. Lets calculate the compounded amount of money you have today for the next 10 years:
M = 100; % Stock today
years = 1:10; % Periods
r = 0.05; % Rate
% Capitalized amount of money over the 10 years
Mcap1 = 100*(1+r).^years.';
% For loop solution
Mcap2 = zeros(10,1);
for y = years.'
Mcap2(y) = 100*(1+r).^years(y); % Or Mcap2(y-1)*(1+r);
end
isequal(Mcap1, Mcap2) % 1
Oleg
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!