Matrix sum
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I'm dealing with a condition in a while loop that I can't get it right. Here is the example:
Given the initial matrix of P=[2 3 8;1 -3 6;-2 -1 0], calculate the e^P = sum(P^k/k!) which k=[0:N-1]. Now the question is how can I implant the sum in matlab? Also, using a while loop, I want to address each element of matrix to meet a condition (e.g. each element of P bigger than 0.5) how can I do that?
0 commentaires
Réponses (1)
Walter Roberson
le 26 Sep 2011
eP = zeros(size(P));
for k = 0:N-1
eP = eP + P^k ./ k!;
end
For your second question, you need to indicate what condition should be used to terminate the "while" loop. Detection of the first element which is not greater than 0.5 ? Detection that you have run out of elements? Which order do you want to visit the elements in, considering that P will be a 2D matrix and thus could be traveled randomly or by rows or by columns or by diagonals or by Knight moves...
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!