Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Newton Raphson's-method

rapidorapido Posts: 2Member
I need to find the two positive roots of f(x) = 60x -(x^2+x+0.1)^6/(x+1)^6 -10x*exp(-x)= 0 with Newton Raphson's method. What I've done is this:

format long

xa = [-0.5: 0.01: 0.5];
xA = [1.5: 0.01: 3];

f = @(x) 60*x - ((x.^2+x+0.1).^6)./((x+1).^6) - 10*x.*exp(-x);

fprim = @(x) (6*((x.^2+x+0.1).^5)*(x.^2+2*x+0.9))/((x+1).^7);

[color=Red]%fprim = @(f,x) diff(f([x])) - I would like to do something like this instead, but it doesn't work for me.[/color]
plot(xa, f(xa))

plot(xA, f(xA))

% startvalues x = 0, x= 2

xstart = [0 2];
for i = 1: length(xstart)
x = xstart(i);
dx = 1;
iter = 0;
disp('x dx')
while abs(dx/x) > 1e-6 && iter<100
dx = -f(x)/fprim(x);
x = x + dx;
iter = iter+1;
disp([x abs(dx)]);

Can anyone see what I did wrong? I guess there is something wrong with my [b]fprim[/b] and that's why I would like to calc this in MATLAB.

As you see I estimate my y=0 to x=0 and x=2. Did I do anything wrong here?

Help is highly appreciated,
Sign In or Register to comment.