Hi,
I'm trying to find the root of a function involving elliptic integrals using Newton's Method to be used in another code. I based my code off of Be Matlabi's answer here: https://www.mathworks.com/matlabcentral/answers/441561-newton-s-method-in-matlab . I'm not too familiar with symbolic toolbox. I keep running into a "Conversion to logical from sym is not possible" error and I'm not sure how to combat this. I already have an idea of what the answer (x) is like, but I need the proper experimental value to replicate a set of plots. The x value will be incredibly close to 1 and the plots I have developed that look similiar have x values like x = 0.999999 (J=1), and x = 997999 (J=2). I really just need help developing this code to give me the proper experimental value for x. The derivative of that function should be correct, but I did do it by hand, so feel free to double-check me if you want to go the extra mile. I also got the derivatives of each elliptic integral from Wolfram's website. Thanks!
clear all
syms f(x) g(x) x
% Constants
B = 1/(2*(1-x)*x);
gN = 625;
J = 2;
tol = 1e-9;
% Functions
[K,E] = ellipke(x);
f(x) = K^2 - K*E - (gN/(8*J^2));
g(x) = B * (3*K*E - E^2 - 3*K^2 - (K^2)*x);
x(1)=0.99; % Initial Point
% Workshop
for i=1:1000 %it should be stopped when tolerance is reached
x(i+1) = x(i) - f(x(i))/g(x(i));
if( abs(f(x(i+1)))<tol) % tolerance
disp(double(x(i+1)));
break;
end
end

 채택된 답변

David Hill
David Hill 2021년 3월 11일
편집: David Hill 2021년 3월 11일

0 개 추천

y=fzero(@nonLinear,[.999,.99999999999999]);
function f=nonLinear(x)
[k(1),k(2)]=ellipke(x);
gN = 625;
J = 2;
f = k(1).^2 - k(1).*k(2) - (gN/(8*J^2));
end

댓글 수: 3

This looks great, David. Could you explain how it works? I don't know much about functions or the fzero command.
fzero() finds the root of the function nonLinear between the two values (.999 and .99999999999999). You can look at matlab's help file.
help fzero
David Hill
David Hill 2021년 3월 12일
If you a satisfied with the answer, you should accept it to close out the question.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 3월 10일

댓글:

2021년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by