It follows the END that terminates the definition of the function "NumIntF" error

조회 수: 4 (최근 30일)
function f =NumIntF(xi,xf)
h=0.001;
N=(xf-xi)/h;
ii=1;
while(ii<= (N+1))
if(ii==1);
x(ii)=xi;
y(ii)= cos(x(ii))*exp(sin(x(ii)))*h;
else
x(ii)=x(ii-1)+h;
y(ii)=y(ii-1)+cos(x(ii))*exp(sin(x(ii)))*h;
end
ii=ii+1;
end
f= y(N+1);
end

채택된 답변

Alan Stevens
Alan Stevens 2020년 11월 2일
Put
xi = 0;
xf = pi; % or whatever your desired start and end values are.
f = NumIntf(xi,xf)
in a script and run that - it worked for me.

추가 답변 (1개)

Alan Stevens
Alan Stevens 2020년 11월 2일
Just change
f=y(N+1);
to
f= y(end);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by