Info

この質問は閉じられています。 編集または回答するには再度開いてください。

What instruction code can i use if i want to update the former parameter value by using the latter parameter value ?

1 回表示 (過去 30 日間)
yang-En Hsiao
yang-En Hsiao 2019 年 3 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I write a code ,and the latter part of code will produce a new parameter value to update the parameter value in the former part of code,what Instruction code can i use to realize what i want ?
For example, part 1 code will produce A,B these two values,
part 2 code will use the A,B value to find the C,D values
part 3 code will let A=C,B=D,and "return to part 2 to find the new C and D value,here we call the new C,D is E,F "
So we find the example above has to update the A,B values,so what instruction code can i use? Is there any example?

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 3 月 1 日
%part 1
A = randi([-9 9]);
B = randi([-9 9]);
for pass_number = 1 : 2
if pass_number == 1
%part 2
C = A.^2 - B;
D = A.^B;
else
E = A.^2 - B;
F = A.^B;
break;
end
%part 3
A = C;
B = D;
end
The break is there because there is no instruction to continue on to part 3 after having found the E and F the second time through part 2.
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 1 日
it means the loop would only process two times. you only defined what should happen for two times.
E and F will not be the newest A and B. You defined A and B as being updated from C and D but you only set C and D once, the first time you go through part 2.
Walter Roberson
Walter Roberson 2019 年 3 月 1 日
What is the reason for wanting C and D to be different variables than E and F ?
A common technique in code is
initialize one or more variables
compute a value based on the variables
compute an error measure
while the error measure is larger than you want
compute new variables based on the current values of the variables
compute a value based upon the new variables
compute an error measure
update the current variables based upon the new variables
end
Perhaps the most common use of this technique with two input variables is in doing a bisection search, possibly for the purpose of finding zeros of a function.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by