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 件のコメント
ROBBIE DEXTER UKAU
2020 年 5 月 13 日
回答 (0 件)
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!