in this code for finding root by newton raphson method i gave derivative of f in g. instead of giving derivative directly how can i get derivative using any code?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
this is a matlab code for finding root for a function using newton raphson method... here i knew derivative of f so that i gave that in g..suppose f is a function whose derivative is little difficult to find, then how can i modify this code for using any function f?
clear
close all
clc
f= @(x) x^4 -x^2 - 80;
g =@(x) 4*x^3-2*x;
x1=3.1;
e=10^-5;
n=100;
for i =1:n
x2= x1-(f(x1)/g(x1));
fprintf('x%d=%.6f\n',i,x2)
if abs(x2-x1)<e
break
end
x1=x2;
end
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!