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!