Plotting a variable after initally guessing the value
8 次查看(过去 30 天)
显示 更早的评论
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
2018-4-17
You can index Zg as well. Also, you shouldn't overwrite the internal function error with a variable.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!