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 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!