【发布时间】:2021-01-18 10:18:59
【问题描述】:
%For this problem write a script file called NC.m that implements
%the Newton-Cotes method of integration for an arbitrary function f(x). It
%should take as inputs the function and the limits of integration [a: b] and
%output the value of the definite integral. Specifically, you should use the
%Trapezoid rule as presented in Equation (11.73)
function [f]= NC(a,b,fun) %newton-cotes
%a and b are limits of intergration
%setting it up
f(a)= fun(a); %y value for lower limit
f(b)= fun(b); %y value for upper limit
%the actual function
f= (b-a)*(f(a)+f(b))/2;
end
我做错了什么?当我输入时, [f]= NC(-3,0,fun) 并设置 fun= @(x)normpdf(x) 。它不断返回“数组索引必须是正整数或逻辑值”。有人可以对此有所了解吗?
【问题讨论】:
标签: matlab math integration