如何解决如何在此代码上实现多个子间隔?
我正在尝试在下面给出的数学假设下优化函数(它实际上将代码中的当前间隔分解为多个子间隔,但是我什至如何实现呢?):
[数学理论]-众所周知,如果将间隔分解成更小的间隔,梯形法则将给出更准确的近似值,从而: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 举报,一经查实,本站将立刻删除。