how to remove NaN from anon function?
1 次查看(过去 30 天)
显示 更早的评论
I am using this simpsons rule, for computing (x)/sin(x), but i receive NaN, and i dont know how to change NaN to zero for anonfunctions. it works fine for functions where I don't run into terms like 0/0, so im guessing I essentially need to remove the very first term/replace it with 0.
if true
% code
function return_value = simpsons(f,a,b,n)
if numel(f)>1
n=numel(f)-1; h=(b-a)/n;
Area= abs(h/3*(f(1)+2*sum(f(3:2:end-2))+4*sum(f(2:2:end))+f(end)));
else
h=(b-a)/n; xi=a:h:b;
return_value=abs(h/3*(f(xi(1))+2*sum(f(xi(3:2:end-2)))+4*sum(f(xi(2:2:end)))+f(xi(end))));
end
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!