Multiply matrix with previous result
Afficher commentaires plus anciens
Hey,
I'm looking to make function that can oversee changes in population. The population is set by having 3 different ages that have different survival rates and possibilities to have children etc. Basicly it goes like this: M*x=b, where M is set propabilities of change for next year, x is the current population number by three groups, and b is the answer for next years number of children, young adults and adults.
M = [0 0 2; 0.25 0 0; 0 0.52 0.73]
x_k = [24; 15; 28]
Now I need to make a loop that multiplys the first population number (x_k) with M, and after that M with previous result.
b = M*x_k
b_2 = M*b
b_3 = M*b_2
etc... until a set amout of years has passed, example 10 years for n = 10
x_k(1,1,1) = [24; 15; 28]
for n=1:10
x(n) = M*x_k(n); %filter
x_k(n+1)=x(n)
end
How could I fix this for loop to get to my desired results? I know my first problem is with x_k(1) since im trying to shove 3 numbers to one variable, but still have trouble typing it differently. Thank you!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!