Trying to use Newton's method until solution converges

So this is probably a dumb question, but I'm terrible at Matlab and am really struggling and can't seem to find any examples for my problem. I understand how Newton's method works, but not sure how to apply it in my case. My problem is I'm trying to solve this equation
for delta_sigma . All the other variables are known already.
This is the code I have right now:
% Variables
Eps = 0.011;
E = 73100;
H = 662;
n = 0.07;
maxIter = 100; % # of iterations
i = 1;
x(i) = 500; % Initial guess
while i <= maxIter
Eps = x/E+2.*(x./(2*H)).^(1/n);
dEps = 2./(n.*x).*(x./(2*H)).^(1/n);
y = x(i)-(Eps/dEps);
i = i+1;
x(i) = y;
end
which I think would be correct if I was trying to find the delta_epsilon value. Could someone help me out? Thanks

 채택된 답변

Torsten
Torsten 2023년 1월 25일
편집: Torsten 2023년 1월 25일
% Variables
Eps = 0.011;
E = 73100;
H = 662;
n = 0.07;
maxIter = 100; % # of iterations
Tol = 1e-8;
i = 1;
error = 1.0;
X(i) = 500; % Initial guess
x = X(i);
while i <= maxIter && error > Tol
f = x/E + 2*(x/(2*H))^(1/n) - Eps;
df = 1/E + 2 * 1/n * (x/(2*H))^(1/n-1) * 1/(2*H);
x = X(i) - f/df;
error = abs(x-X(i));
i = i+1;
X(i) = x;
end
i
i = 7
X
X = 1×7
500.0000 802.8180 765.4778 756.0581 755.6437 755.6430 755.6430
x/E + 2*(x/(2*H))^(1/n)- Eps
ans = 0

댓글 수: 4

Wow thanks so much!
Could you explain why you have error as 1?
Torsten
Torsten 2023년 1월 25일
편집: Torsten 2023년 1월 25일
You can choose any value > "Tol" for "error". It's only an initialization such that the while-loop is entered.
A value for error <= 1e-8 won't work because MATLAB then assumes that a solution has already been found.
Wow thanks so much!
@Christina Kersten If so, you should accept-click Torsten's asnwer

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2023년 1월 25일

댓글:

2023년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by