Integral3 with vector-valued function

10 ビュー (過去 30 日間)
Alexander Ruderer
Alexander Ruderer 2020 年 10 月 21 日
コメント済み: Walter Roberson 2020 年 10 月 21 日
Hi, I have a qustion regarding the predefined matlab-function integral3.
Is it possible to do a vector-valued 3D integration?
With the one-dimensional function integral it is very easy:
Example:
fun = @(x)sin((1:5)*x);
q = integral(fun,0,1,'ArrayValued',true)
Yet the same syntax is not possible for integral 3.
Example:
fun = @(x,y,z) x.^(1:100) .* y .* z ;
q_array = integral3(fun,0,1,0,1,0,1,'ArrayValued',true);
This throws the error ''ArrayValued' is not a recognized parameter. For a list of valid name-value pair arguments, see the
documentation for this function.''
So is there a way to circumvent this behaviour?
In the moment, I solved it with a simple for-loop. But unfortunately the run-time is quite bad. So I hoped to lower the run-time with an vector-valued 3Dintegration.
  1 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 10 月 21 日
@Analyst BugB, why are you posting the same image (which opens a pop-up window in the browser), using different account names. Is this some sort of website testing, or are you trying to find a bug?

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 21 日
Not possible with integral3(). Following shows an alternative
fun = @(x,y,z,n) x.^n .* y .* z ;
q_array = arrayfun(@(n) integral3(@(x,y,z) fun(x,y,z,n),0,1,0,1,0,1), 1:100)
  2 件のコメント
Alexander Ruderer
Alexander Ruderer 2020 年 10 月 21 日
Thank you very much, for your answer.
Your code works and makes my for loop unnecessary. So I will switch on your lines to make my code simpler. Yet, unfortunately it does not really lower the run-time. The for loop and your code had nearly the same run-time in a short-test.
I also tested the 1D example. There the array-valued option is able to more than half the run-time.
So I hoped, that this is also possible with integral3, but proabably the functions have different implementations regarding vector-valued functions.
Walter Roberson
Walter Roberson 2020 年 10 月 21 日
https://www.mathworks.com/matlabcentral/fileexchange/47919-integraln-m might give ideas

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

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by