how to improve my coding

.can anyone help me with this question
The equation of 1/x=1+x^3 has one positive solution. Plot the two graphs y=1/x and y =1+x^3
together on the same set of axis to demonstrate that there is one solution. Use Newton’s
method to find it correct to six decimal places. Put the results in a table.here is my attempt .i dont know what else to add.
f=@(x)+(x^3)-(x^1);
fd=@(1)+(3(x^2))+(x^-2));
a= round (input ('Enter Your Initial Value(x) :'),1);
tol = 0.0002; % 4 decimal places
fa = round(feval (f,a),1);
fda = round(feval (fd,a),1);
al = round((a-(fa/fda)),1);
error = round(abs((al-a)/al),1);
iter =0;
disp (' n Xn F(x) F(x) Xn+1 Error')
disp (' -----------------------------------------------------------')
while (error>= tol)
iter = iter+1;
al = round(a-(fa/fda),1);
fal = round(feval(f,al),1);
fdal = round((feval(fd,al)),1);
error = round(abs(((al-a)/al)*100),1);
fprintf('%2i\t %f\t %f\t %f\t %f\t %f\t \n',iter,a,fa,fda,al,error)
if (error>=tol)
a = al;
fa = fal;
fda = fdal;
end
end

2 comentarios

Rik
Rik el 13 de Mayo de 2020
For another question about the same assignment, see here.
ROBBIE DEXTER UKAU
ROBBIE DEXTER UKAU el 13 de Mayo de 2020
thank you for your respond .i'll try to see what i can change .didn't expect to find someone who have the same question as me.

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Preguntada:

el 13 de Mayo de 2020

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by