matlab 循环求积
我正在尝试使用 matlab 数值积分函数,例如循环中的四边形。但我也想让matlab计算我对几个积分极限的积分:
p=1;
q=3;
for k=1:5
a=0;
b(k)=k.*10;
integrand(k)=@(v)(v-a).^(p-1).*(b(k)-v).^(q-1);
p(k)=quad(integrand,a,b(k));
end
这确实看起来我很聪明:)但是Matlab没有想法:( 感谢您的帮助! 毫克
I'm trying to use matlab numerical integral functions,for example quad in a loop. But I also want to let matlab to calculate my integral for several integral limits:
p=1;
q=3;
for k=1:5
a=0;
b(k)=k.*10;
integrand(k)=@(v)(v-a).^(p-1).*(b(k)-v).^(q-1);
p(k)=quad(integrand,a,b(k));
end
It really seems me clever:) but Matlab has no Idea:(
Thank you for any help!
mg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您遇到的主要问题是您使用
p
既作为参数又存储集成结果。因此在循环内p
变成一个向量,然后它不能用作被积函数中的幂。我不知道为什么,但我似乎还需要删除k
作为b
和integrand
的索引。但这段代码似乎有效:I think the main problem you have is that you're using
p
both as a parameter and also to store the results of your integration. So within the loopp
becomes a vector, and then it can't be used as a power in the integrand. I'm not sure why, but I also seem to need to removek
as an index intob
andintegrand
. But this code seems to work:似乎您可以使用额外的参数定义被积函数,所以
但是当我运行时它仍然给出错误:
不太确定您要做什么......
Seems like you could define integrand with an extra parameter, so
but when I run it still gives an error:
Not exactly sure what you're trying to do though ...