How can I replace inline

조회 수: 6 (최근 30일)
Mercedes Luna
Mercedes Luna 2023년 1월 18일
답변: Steven Lord 2023년 1월 18일
function x = rfNewtonR(fun,x,TolX,itmax)
y(1)=x;
dif=diff(sym(fun));
d=inline(dif);
for i=1:itmax
y(i+1)=y(i)-((fun(y(i))/d(y(i))));
err(i)=abs((y(i+1)-y(i))/y(i));
fprintf('for %d iteration ans is %0.3f %0.2f\n',i,y(i),err(i));
if err(i)<TolX %checking the amount of error at each iteration
break
end
if(isnan(err(i)))
msg = 'rfNewtonR: Iteration Limit Exceeded';
error(msg);
end
end
x=y(i);
end

답변 (1개)

Steven Lord
Steven Lord 2023년 1월 18일
To convert a symbolic expression into something you can evaluate numerically use the matlabFunction function.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by