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
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
Matt Fig 2011년 1월 26일
This question is really vague. Please provide a small, succinct example of input data and output data.
Santosh Kasula
Santosh Kasula 2011년 1월 26일
Khaleel, I just made your question more descriptive.

댓글을 달려면 로그인하십시오.

 채택된 답변

the cyclist
the cyclist 2011년 1월 26일

3 개 추천

Yes, a loop in MATLAB is very similar to a loop in Java, but the syntax is a little different. (Of course, that statement could be made between almost any two programming languages.)
In MATLAB, you might also be able to calculate future value in a vectorized way, where you calculate values from all future time periods in one line. (I am guessing that you are talking about future value as defined in finance.)
As alluded to in the comments, a vague question will buy you a vague answer. Please add some detail if you want detailed answers.

댓글 수: 1

cool
cool 2011년 1월 26일
yeah it's the on for finance. F = P(1+i)^n
a program to calculate the future value for each year separately.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Oleg Komarov
Oleg Komarov 2011년 1월 26일

2 개 추천

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에 대해 자세히 알아보기

제품

질문:

2011년 1월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by