24小时热门版块排行榜    

查看: 517  |  回复: 0

engine9817

铜虫 (小有名气)

[求助] 求设计一个被积分函数中需要解方程的积分程序

如果有一个被积方程为G(x,y),积分区间假设为(1,2)
其中y的值与x是由另一个函数决定如f(x,y)=0; 这个式子不能直接得到y的解析式,复杂点的话,可能一个x有多个y值,但只有一个合适,如正的或实的。
这样在求积G(x,y)时,对应于每个x都要求解一个y值,还可能要对y值进行筛选。
我一开始在function文件里面设计了G(x,y)的程序.方便起见,我们假设
f(x,y)=x-y^2=0; 假设这里把y解析表示,要求用fsolve解出y

function integrandfun=G(x)

y=fsolve(@(t) x-t.^2, 1);  

integrandfun=x.^2+y;

主函数中调用 这个方程积分如

In=quadgk(@(x) integrandfun, 0,1);

结果是: 3.558078204809361与直接积分x.^2+sqrt(x)的结果3.552284749830793有差别
提示:
警告: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm
instead.
> In fsolve at 285
  In fkk at 3
  In @(x)fkk(x)
  In quadgk>evalFun at 330
  In quadgk>f1 at 348
  In quadgk>vadapt at 249
  In quadgk at 188
  In figures at 12

No solution found.

fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the default value of the function tolerance.

<stopping criteria details>

请问有进一步的优化吗?事实上如果把f(x,y)变得复杂点,积分存在更多问题。
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 engine9817 的主题更新
信息提示
请填处理意见