Integrating a function over an array of coordinate

7 ビュー (過去 30 日間)
Jacob Williams
Jacob Williams 2017 年 12 月 2 日
Hi I'm looking to evaluate an integral w.r.t T over a 3D mesh grid array of coordinates and I'm not quite sure how to do it.
Currently I have this but it doesn't work and I'm not sure why:
% Function to evaluate theta w.r.t T over a 3D meshgrid
[X, Y, Z] = meshgrid(0:1:10, 0:1:10, 0:1:10);
fun = @(T) (T.*((x.^2)+(y.^2)+(z.^2)));
fun2 = @(x,y,z) integral(fun,0,inf);
theta = arrayfun(fun2, X, Y, Z);
Any help would be greatly appreciated Thanks!

回答 (2 件)

John D'Errico
John D'Errico 2017 年 12 月 2 日
You CANNOT use integral on a function defined on a list or array of points. Just wanting code to do what it is not programmed to do is a waste of time.
Instead, use a tool that is designed to solve your problem.
help trapz
  1 件のコメント
Jacob Williams
Jacob Williams 2017 年 12 月 2 日
That doesn't answer my question, I am looking to integrate over a 3D grid of coordinates, I understand that I can't currently do that and that is not what the code is programmed for, hence why I am looking for a different solution.
trapz is not that solution as it is only 2D and in future you could be less condescending in your answer

サインインしてコメントする。


Prajwal Gowdru Shanthamurthy
Prajwal Gowdru Shanthamurthy 2021 年 4 月 20 日
I didn't really understand the integral you're trying to compute. I'm not sure if this might help. Please take a look.

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by