simpsons rule for integration with multivariable
2 次查看(过去 30 天)
显示 更早的评论
I am having trouble setting up the equation.
supposedly, I am trying to fine the integral of 0.7051*r.*T from 0.308 to 0.478
both r and T are vectors.
so far I have @f = @(r,T) 0.7051*r.*T
a = 0.308
b = 0.478
n = length(r) to be number of subdivisions
h = (0.478-0.308)/10 to be step size
The following is my approach so far I= h/3*(f(r(1),T(1))+2*sum(f(r(3:2:end-2),T(3:2:end-2)))+4*sum(f(r(2:2:end),T(2:2:end)))+f(r(end),T(end)))
I am not sure if I need to use a for loop to include all a,b,and h input or this (I) is good....
0 个评论
回答(1 个)
Roger Stafford
2017-11-14
There is some confusion here as to what your variable of integration is to be. In the way you define ‘h’ it would appear to be some variable that varies from 0.308 to 0.478 in ten discrete steps. But how does that relate to the two vectors ‘r’ and ’T’ with their ’n’ values? You would need for 'n' to equal eleven to be compatible with the ten in the definition of ‘h’.
Also the term “+4*sum(f(r(2:2:end),T(2:2:end)))” looks incorrect. It should be “+4*sum(f(r(2:2:end-1),T(2:2:end-1)))”.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!