Borrar filtros
Borrar filtros

Matrix sum

4 visualizaciones (últimos 30 días)
Kevin
Kevin el 26 de Sept. de 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?

Respuestas (1)

Walter Roberson
Walter Roberson el 26 de Sept. de 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...

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by