フィルターのクリア

Matrix sum

4 ビュー (過去 30 日間)
Kevin
Kevin 2011 年 9 月 26 日
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?

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 9 月 26 日
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...

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by