Matlab quad


1x32x5dx, (from 0 to 1)

write a function myfun that computes theintegrand:

function y = myfun(x) 
y = 1./(x.^3-2*x-5);

Then pass @myfun, a function handle to myfun,to quad, along with the limits of integration, 0 to 2:

Q = quad(@myfun,0,2)

Q =

   -0.4605

Alternatively, you can pass the integrand to quad asan anonymous function handle F:

F = @(x)1./(x.^3-2*x-5);
Q = quad(F,0,2); 

转载于:https://www.cnblogs.com/vigorz/p/10499169.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Matlab中,quad函数用于数值积分。它的格式为quad(fun,a,b,tol),其中fun是被积函数,a和b是积分区间的左右端点,tol是积分精度要求,默认值为10^-6。例如,可以使用quad函数计算函数f(x) = 1/(1+x^2)在区间\[0,1\]上的积分,代码如下所示: f = matlabFunction(1./(1+x.^2)); I = quad(f,0,1)。\[1\] 另外,Matlab还提供了fminbnd函数用于在给定区间内寻找函数的最小值。它的格式为\[xVal,fval,exitflag,output\] = fminbnd(fun,a,b),其中fun是要最小化的函数,a和b是搜索区间的左右端点,xVal是找到的最小值的位置,fval是最小值,exitflag是退出标志,output是优化过程的输出信息。例如,可以使用fminbnd函数找到函数fun(x) = exp(sin(x))*exp(cos(x)+1)*(cos(x)+abs(x))在区间\[-10,10\]上的最小值,代码如下所示: fun = @(x)exp(sin(x))*exp(cos(x)+1)*(cos(x)+abs(x)); \[xVal,fval,exitflag,output\] = fminbnd(fun,-10,10)。\[2\] 此外,Matlab还提供了fsolve函数用于求解非线性方程组。它的格式为x = fsolve(fun,x0),其中fun是包含方程组的函数,x0是初始猜测值,x是求解得到的方程组的解。例如,可以使用fsolve函数求解方程组Example3_15_Fun(x) = \[exp(exp(x(1)+2*x(2)))-x(1)*x(2)^2; x(1)*cos(x(2))+x(2)*sin(x(1))-1\],代码如下所示: function y = Example3_15_Fun(x) y = zeros(2,1); y(1) = exp(exp(x(1)+2*x(2)))-x(1)*x(2)^2; y(2) = x(1)*cos(x(2))+x(2)*sin(x(1))-1; x = fsolve(@Example3_15_Fun,\[0 0\])。\[3\] #### 引用[.reference_title] - *1* [matlab的常见函数(一)](https://blog.csdn.net/m0_73511691/article/details/128052092)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [matlab第三章笔记](https://blog.csdn.net/weixin_45912723/article/details/125320905)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值