Problems with Newton/Raphson & other root finding methods
2 views (last 30 days)
Show older comments
Ok so I have the code intact, I just need to know how to skip the first iteration because using the backwards approximation method will return a NaN on the first iteration.
I can't use all the fun stuff like syms, and dsolve and just plop those into the f'(x) in the denominator of the equation xr=x1-(f(x1)/f'(x1))
clc; clear all;
%Assignments from given data
d=3.612; %Density in kg/m^3
v=20; %Velocity in m/s
m=.00001825; %Dynamic Viscosity in N*s/m^2
l=20; %Length in meters
D=.5; %Diameter in meters
n=.0001; %Surface roughness of pipe in meters
Re=(d*v*D)/m;
%Assignments from me
x0=.000001;
x1=.999999;
e=1e-3;
i=0;
f=@(x) (-2.0*log10((((n/D)/3.7))+(2.51/(Re*(sqrt(x))))))-(1/sqrt(x));
while i<1000
xr(1)=
xr=x1-(f(x1)/((f(x1)-f(xr))));
i=i+1;
if i > 1
if abs(xr)>0
ea=abs((xr-xrold)/xr)*100;
if abs(ea)<e
break
end
end
end
xrold=xr;
end
fprintf('f= %8.6d',xr);
4 Comments
John D'Errico
on 23 Feb 2019
The point is, we really don't give a hoot about your skill at coding, or the degree that it may suck. It may. It may not. However, IF you want help on your problem, you are best served by giving information about the problem. That makes it more likely to attract someone who can both answer your question and who is willing to invest their time to answer you.
By suggesting that you have at least some interest in the outcome, you also make it more likely that someone will be willing to help you. Conversely, if you shout to the world nothing more than that your skills suck, that also suggests that you really don't care about learning to improve.
Personally, I am very willing to help people who seriously want to be better, but if someone is interested in nothing more then getting a passing grade, then I'm far more likely to just skip over the question, regardless if I could have answered it.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!