Plotting a variable after initally guessing the value

조회 수: 8 (최근 30일)
Sean Sullivan
Sean Sullivan 2018년 4월 17일
댓글: Rik 2018년 4월 17일
I am trying to use a numerical method to find out the answer to a function. I use an initial guess and iterate until the answer is correct. I am trying to plot Zg vs. D, but cannot figure out how to save Zg after each iteration of D.
Zg = 1; D = 1:1:20; error = 5; A = 100; for i = 1:length(D)
while error >= 1
if D(i) <= 10
P = 5*D(i) * Zg;
else
P = D(i) * Zg;
end
error = ((A-P)/A)*100;
Zg = Zg +1;
end
end
  댓글 수: 1
Rik
Rik 2018년 4월 17일
You can index Zg as well. Also, you shouldn't overwrite the internal function error with a variable.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by