MATLAB Answers

Integrate PDEPE solution wrt x

5 views (last 30 days)
I have solved a 1D spherical Diffusion PDE using pdepe in Matlab, which has given me Concentration(x,t) {= } as a 2D array Now in continuation of my research, I need to find Stress as a function of distance and time {= }, whose expression has terms of and . How should I tackle this part, ie, integrate x^2.C(x,t) wrt x.


Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 17 Jun 2020
This rather straightforward method should get the job done (assuming you cannot get away with simply use trapz, or cumtrapz, but will definitely need the integral at "all" points in x and y and not only the ones you got out of the PDE-solution of C):
C = peaks(123); % Just making up some mock-up data
x = 0:122; % and X
t = 0:122; % and t-coordinates
[X,T] = meshgrid(x,t);
I1 = @(t,a,b) integral(@(x) interp2(X,T,P,x,t),a,b)
% this gives you a function to evaluate for any time and point along x,
% below for time 12 s integration boundaries from 3 to 37


Jayant Choudhary
Jayant Choudhary on 19 Jun 2020
This works well for integrating C(x,t). But here we need int of x^2*C(r,t). General thought would be to create new C' matrix? Which is basically = x^2*C(r,t). But again, how can i create this, ie multiple specific cells with those values of x? (Pardon me for small questions, I have recently started with Matlab)
Bjorn Gustavsson
Bjorn Gustavsson on 19 Jun 2020
Ok, if you're a recent matlaber, then I guess the anonymous functions are one of the most tricky parts to wrap your head around. Take some time to really grasp that construct.
In this case you don't integrate a matrix, in my solution you integrate a function where the function calculates the function-values by interpolation of the C matrix for an arbitrary point in time and along all values of x that the integral-function asks for. That way you should be able to modify the function I used to something like:
@(x) x.^2.*interp2(X,T,P,x,t)
Instead of what I used.
Jayant Choudhary
Jayant Choudhary on 19 Jun 2020
Thankyou so much, it works very well.

Sign in to comment.

More Answers (0)