I have a function dependent on both xp and t, which I need integrated over a meshgrid of X,Z. This is a slightly simplified version of the equation:
z=-0.000150:0.000005:0;
x=0.000300:0.000005:0.000100;
[X,Z]=meshgrid(x,z);
syms xp
syms t
F=@(xp,t) ((1/t).*(exp((-1).*(((X-xp).^2)+(Z.^2))/(4.*t))));
I need to integrate t between 0 and 0.0002, and xp between 0 and 0.000100 across the X,Z array. I know I can make a single integral ArrayValued, but I can't work out the best way to do the double integral. All suggestions welcome! Thanks!

Antworten (1)

Star Strider
Star Strider am 11 Jul. 2016

0 Stimmen

I would just use trapz:
z=-0.000150:0.000005:0;
x=0.000300:-0.000005:0.000100;
[X,Z]=meshgrid(x,z);
F=@(xp,t) ((1./t).*(exp((-1).*(((X-xp).^2)+(Z.^2))./(4.*t))));
Fmtx = F(X,Z); % Create Matrix
Fint = trapz(trapz(~(isnan(Fmtx)))); % Integrate
To use the Symbolic Toolbox, the correct function is int, not integral.

3 Kommentare

Torsten
Torsten am 11 Jul. 2016
I thought xp and t were the variables of integration whereas X and Z were constants ...
But maybe I'm mistaken.
Best wishes
Torsten.
Felicity Freeman
Felicity Freeman am 11 Jul. 2016
Torsten, You are right. X and Z are constants, whose values are defined in arrays. The integration variables are xp and t. Felicity
Star Strider
Star Strider am 11 Jul. 2016
For 'ArrayValued' to work, the integrand has to be an actual array.
For example:
A = @(x,y) [x,x+y;x-y,y];
Q = integral(@(y) integral(@(x)A(x,y) ,0,2, 'ArrayValued',true), 3,5, 'ArrayValued',true)
That works.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 11 Jul. 2016

Kommentiert:

am 11 Jul. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by