Clear Filters
Clear Filters

Matrix sum

4 views (last 30 days)
Kevin
Kevin on 26 Sep 2011
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?

Answers (1)

Walter Roberson
Walter Roberson on 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...

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!