MATLAB Answers

Solving nonlinear equation using newton-raphson method

3 views (last 30 days)
SmallBigPapaSmurf
SmallBigPapaSmurf on 4 Apr 2020
Edited: Matt J on 4 Apr 2020
Hello, I have this code that is wrong. I want to solve an equation (f) using newton's method. I want to update my old V value to the eqation for f and df, but I just can't get my head wrapped around it. Could anyone help please?
NB: The answer should be 0.86728 assuming the initial value of V is 0.
P=6;
T=2;
N = 500;
tol = 0.0001;
V = zeros(1,N);
f = zeros(1,N);
df = zeros(1,N);
del = 0;
Vnew = 0;
while del < tol
for i = 2:N
V(i) = Vnew;
f(i) = 3*P*V(i).^3 - P*V(i).^2 + 9*V(i) - 8*T*V(i).^2 - 3;
df(i) = 9*P*V(i).^2 - 2*P*V(i) - 16*T*V(i) + 9;
Vnew = V(i-1) - (f(i)/df(i));
end
del = V(i) - V(i-1);
end

  0 Comments

Sign in to comment.

Accepted Answer

Matt J
Matt J on 4 Apr 2020
Edited: Matt J on 4 Apr 2020
i=0; del = Inf;
while del > tol && i<N
i=i+1;
f(i) = 3*P*V(i).^3 - P*V(i).^2 + 9*V(i) - 8*T*V(i).^2 - 3;
df(i) = 9*P*V(i).^2 - 2*P*V(i) - 16*T*V(i) + 9;
V(i+1) = V(i) - (f(i)/df(i));
del = abs(V(i+1) - V(i));
end
lastValue = V(i+1),

  0 Comments

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!