Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 2 (최근 30일)
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