问题描述
我正在尝试在下面给出的数学假设下优化函数(它实际上将代码中的当前间隔分解为多个子间隔,但是我什至如何实现呢?):
[数学理论]-众所周知,如果将间隔分解成更小的间隔,梯形法则将给出更准确的近似值,从而:I1 = [a; b1],I2 = [b1; b2],I3 = [b2; b3],...,I n-1 = [b n-1,bn]其中bn = b。从上面编写一个使用您的NC.m代码实现此策略的程序。它应该能够完成任意n个任务。必须创建多少个子间隔才能在间隔[-3:0] 上获得下面列出的函数的“准确” 积分近似值?
%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 takes 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 integration
%setting it up
fa= fun(a); %y value for lower limit
fb= fun(b); %y value for upper limit
%the actual function
f= (b-a)*(fa+fb)/2;
end
%result from estimation
%fun= @(x) normpdf(x)
%[f]= NC(-3,fun)- 0.6051
%not accurate when compared to results from actual calculation
%syms x
%f= normpdf(x);
%a= -3;- lower limit
%b= 0;- higher limit
%int(f,a,b)- 0.4897
请帮助。不胜感激!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)