Newton Raphson method of finding multiple roots

7 views (last 30 days)
I'm trying to find multiple roots of an equation using the newton raphson method (must be newton raphson). I have code which can find one root, however for my specific parameters there are 12 roots to find. (Pos/neg of 6 values.) I need to have all of the roots, not just the first one my code finds.
here is my code, thanks
clear; clc; close;
% guess value for root
x = input('Enter a seed value for x: ')
% Get acceptable Error
err = 0.01
% formula coefficients used
L = 0.8
Bi = 0.5
ferr = 100; % initializing acceptable error for while loop
Fold = 100; % initializing old F value for while loop
f1 = (x*L)/(Bi); % function 1
f2 = cot(x*L); % function 2
f = f1-f2; % difference between functions
f1p = (L/Bi); % Derivative of function 1
f2p = -L*csc(L*x)^2; % derivative of function 2
fp = f1p-f2p;
while abs(f) > err % difference of the functions is greater than error
f = (x*L/Bi)- cot(x*L); % function again so it re-evaluates inside loop
fp = (L/Bi) + L*csc(L*x)^2; % derivative again so it re-evaluates inside loop
Fold = f; % update old F value for newtons formula use
x = x - f/fp % update x value to get closer to real root
ferr = f - Fold; % update function error (not really useful here)
pause(1)
end
x1 = -3.5*pi:.1:3.5*pi;
f1 = (x1*L)/(Bi); % function 1
f2 = cot(x1*L); % function 2
plot(x1,f1,'color','r');
hold on;
plot(x1,f2,'color','b');

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!