matlab - 如何在此代码上实现多个子间隔?
问题描述
我试图在下面给出的数学假设下优化函数(它基本上将代码中的当前间隔分解为多个子间隔,但我什至如何实现它?):
[数学理论]- 众所周知,如果将区间分解为更小的区间,梯形规则会给出更准确的近似值,因此: 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,0,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
请帮忙。这将不胜感激!
解决方案
推荐阅读
- verilog - 在verilog中从PRBS生成器向错误检查模块提供输入
- javascript - 如何用 HTML 元素替换 jQuery 对象?
- javascript - 如何更新幻灯片数量(猫头鹰轮播)
- spring-mvc - 如何在我的 Spring MVC REST 控制器中接受多个多部分文件
- python - 从 MySQL(SQLAlchemy) 读取后需要帮助编写 bonobo XML writer 转换
- angular - Angular4 - 无法绑定到“vgHls”,因为它不是“视频”的已知属性。
- python - 如何使用 swig 将 c++ int** 返回值类型映射到 python
- tensorflow - ResnetV2 Graph 乱七八糟
- php - Laravel - 将表列值转换为 slug
- php - 我的网站搜索查询不起作用