Problems with Newton/Raphson & other root finding methods

2 views (last 30 days)
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
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.
Terry Poole
Terry Poole on 24 Feb 2019
Look here bud, I took it the first time, I even apologized for a sin I ddnt even realize I had commited. So how about I tell YOU the point.
The point is I am a 36 year old man who ON TOP of being a full time aerospace engineering student works 12 hour shifts. I dont have mom and dad paying my bills and tuition, I dont even have financial aid. I PAY IT, out of my pocket so that maybe someday soon I can provide a better life for my family. So am I looking for a passing grade? You bet your butt I am, my whole life is invested into this.
What I'm not looking for is scorn, ridicule and condescension. So if you don't want to help, thats fine. Don't! I've spent almost 50 hours on this stupid code, am going behind in all of my other classes (Dynamics, Mechanics of Materials and Fluid Dynamics) and have 2 exams this week to study for. So excuse me for reaching out for a tiny bit of guidance. I'm not asking for someone to write the code for me. Just to show me what I'm doing wrong! I went to my teacher and he told me to find a tutor, I dunno maybe its a programming thing that forces anyone with the knowledge to do this to be hateful, but how am I supposed to learn to do this if all anybody wants to do is tell me how bad of a person I am?
Thanks for all of your welcome advice, I'll remember it in the future when I take the failing grade before I ask anyone for help again.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!