How to pass an array into the initial condition function while using pdepe

I have a PDE which is solved using pdepe. However after the solution (1xn array) is achieved, i perform some other calculation and then i want to feed the end result back into the PDE (in the next iteration in a for loop) as initial condition. How can this be achieved.
Additinally how can additional paramters be passed into the pde function?

 Réponse acceptée

Torsten
Torsten le 20 Avr 2023
Modifié(e) : Torsten le 20 Avr 2023
However after the solution (1xn array) is achieved, i perform some other calculation and then i want to feed the end result back into the PDE (in the next iteration in a for loop) as initial condition.
Define
icfun = @(x)interp1(X,U,x)
where X is the mesh vector and U is the vector of initial values corresponding to X you want to feed back into the solver for the next iteration.
Additinally how can additional paramters be passed into the pde function?

4 commentaires

Thank you very much. Wouldnt X and x in (icfun = @(x)interp1(X,U,x)) be the same? Mesh vector is the spatial mesh which we usually define as x using linspace command before the pdepe.?
Also where should the line of code you mentioned be placed?
Wouldnt X and x in (icfun = @(x)interp1(X,U,x)) be the same?
No. x is nothing but a formal parameter the function icfun is called by from pdepe. interp1 searches for the location of x in your vector X and returns the corresponding (maybe interpolated) value u from the vector U.
I assume that the spatial region of integration remains the same in both problems ?
Also where should the line of code you mentioned be placed?
icfun is input to pdepe. So it should be defined after you got the results from your first call to pdepe and put into the list of inputs to pdepe for your second call to pdepe.
That means naming the mesh vector with ‚x‘ is not a good idea. So It’s better to rename the meshvector with X and then use x for interpolation. Right?
Torsten
Torsten le 20 Avr 2023
Modifié(e) : Torsten le 20 Avr 2023
x is just a formal parameter - MATLAB does not expect it to have a value when you define the function "icfun". It will not conflict with variables explicitly set in your code. Simply make sure that X and U in your definition of "icfun" are your solution mesh vector and your solution from the first call to "pdepe". The name "x" can be replaced by any other name in the definition of "icfun".
Maybe before proceeding you should pass the free MATLAB online tutorial:

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by