Hello,
I want to plot my code. It's newton-raphson method code. But I musn't change the while loop. In the question it is given that "use while and if statement".
When I write the plot, Matlab gives me a blank graph. So I exclude the " plot" when I'm sharing the code with you.
NOTE : . I want 2 graphs, one is f(x) versus i and one is x versus i. Also how can I write a function for the circle mark for each data point in the function?
( I use Matlab R2015a )
Thank You.!!
clcclear allclose allfprintf('%10s %10s %10s %10s %10s\n','i','xi','f(xi)','diff_f(xi)','|Ea|')Ea = 100;m = 0 ;x = 0;while abs(Ea) > 10^(-3) if m <= 50 f = @(x) x^3 - x - 3 ; diff = @(x) 3*(x^2) - 1 ; xnew = x - (f(x) / diff(x)); Ea = (((xnew-x)/xnew)*100); fprintf('%10.4f %10.4f %10.4f %10.4f %10.4f\n',m,x,f(x),diff(x),abs(Ea)) x = xnew; else break end m = m+1; end
Best Answer