Matlab Integral function for a self teaching beginner
古いコメントを表示
I need to take an integral over a meshgrid of space and time.
at each point in space and time I need to take an integral and Im having trouble understand the integral command.
To simplify I need
where t is time an x is space and c is what im integrading over.
I believe that
t=0:1:10
x=0:1:10
[time space]=meshgrid(t,x)
fun=@(c) time+space+c
answer=integral(fun,-10,10)
So why does this not work but
answer=integral(fun,-10,10,'ArrayValued',1) does?
Im trying to conceptualy understand
採用された回答
その他の回答 (1 件)
By default, integral calls the integrand function you pass into it with an array of data, not just a scalar. It requires your integrand function to return an array the same size as the input as output. Each element of the output represnts the value of your integrand function at the corresponding element of the input.
In your code:
t=0:1:10;
x=0:1:10;
[time space]=meshgrid(t,x);
fun=@(c) time+space+c;
that would only work if c was compatibly sized with time and space. One example of a c that's compatibly sized is a scalar.
fun(42)
One example of a c that's not compatibly sized with time and space is a 1-by-2 vector. Adding an 11-by-11 matrix and a 1-by-2 matrix is not mathematically defined.
fun([42, -1])
But you have no control over the size of the data with which integral calls your function, unless you explicitly tell it "My function returns an array of data, so just call it with a scalar each time". That's what the 'ArrayValued' name-value argument tells integral if you specify that the value of that name-value argument as 1.
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!