command asking to repeat previous step

[EDIT: 20110728 14:37 CDT - reformat - WDR]
Hello.. my question is: How to write programming code asking to return to the previous step i.e if A=B; we hv to return to step 2 (do all over again starting from step 2). my code is
for s = 1:23
d{s,1} = b{s,1}*(b{s,1})';
A{s,1} = eig(d{s,1}); %Find the eigenvalues
anyNegativeA = any(A(:)<0); %thanks to 'the cyclist' for the code..
if anyNegativeA; %checking if there's any entries in -ve value.
B = A*2;
end
end
...and now, what's the command asking to repeat the 'find the eigenvalues' step

1 件のコメント

Nur Najiha
Nur Najiha 2011 年 7 月 28 日
owh.. how to write the code properly in here.. sorry .. i really dont know how to do that...

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2011 年 7 月 28 日

0 投票

If A=B then because B=A*2, it must be the case that A=A*2 . That can only be true if every entry in A is one of (0, infinity, -infinity, or NaN). Note though that if that is the case, the only one of those that is negative for the anyNegative test is -infinity, so the B=A*2 test would only be invoked if at least one of the eigenvalues comes out as -infinity.
After you change B, that does not feed back to changing anything that is used do calculate the eigenvalues. The eigenvalues are determined entirely based upon the cell array "b" indexed at "s", but you have not changed "b" or "s". Going back and recalculating the eigenvalues would give you the same result, so you would infinite loop.
I think you need to reconsider your logic.

2 件のコメント

Nur Najiha
Nur Najiha 2011 年 7 月 28 日
emmm.. actually B=A*2 is just dummy.. the real is B = A.*phi-diag(diag(A)).. just as an example.. i just wanna know how to write the command asking to repeat previous step.. tq for ur cooperation..
Walter Roberson
Walter Roberson 2011 年 7 月 28 日
In this circumstance, the command asking to repeat the previous step can be optimized to the following code:
%
That is, the empty comment.
Repeating the previous step is not going to produce a different outcome than before unless you change "b" or "s".
For whatever good it does you:
while true
%do your eig computation here
if condition_to_exit_is_true; break; end
%change whatever variables needed to make the next eig round different
end

サインインしてコメントする。

その他の回答 (2 件)

the cyclist
the cyclist 2011 年 7 月 28 日

0 投票

Nur, the things you are asking are very basic MATLAB questions, or really even just very basic programming questions. This is not really a very good place to learn basic programming. I suggest, if you want to learn the basics of MATLAB, to thoroughly digest this:

2 件のコメント

Nur Najiha
Nur Najiha 2011 年 7 月 28 日
yup.. tq for the link.. i'll learn it slowly.. by the way, is there any suggestion from u? :)
the cyclist
the cyclist 2011 年 7 月 28 日
My guess is that you actually will want to use a "while" loop structure, which typically better for situations where you want to check whether a certain condition is true, then run the loop again depending on the result.

サインインしてコメントする。

Nathaniel Ewing
Nathaniel Ewing 2012 年 4 月 29 日

0 投票

@the cyclist
Unfortunately this is what's happening in engineering schools right now. I'm currently a mechanical engineering student, and what they've done to the curriculum is basically throw you into an engineering lab without knowing any matlab or even basic programming. It's a big shock and it's hard to learn Matlab while trying to get a good grade in a lab. Fortunately they're starting to restructure so next year's freshman will be taking all beginning programming their freshman year as well.

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by