How to set a vector as initial condition for PDEs?

4 views (last 30 days)
I'm trying to set a vector, Cini, containing a spatially-varying quantity as my intial codition in a pde for all except the first instance of a loop (in this instance, initial condition is uniform for r<=R1). In the current wrong syntax (below), it's tripping the code up. How do I go about correctly implementing this?
function c0 = pdex2ic(r)
if r <= R1
if i==1
c0 = C0;
else
c0 = Cini;
end
else
c0 = 0;
end
end

Accepted Answer

Torsten
Torsten on 23 Dec 2022
Edited: Torsten on 23 Dec 2022
Generate two data vectors R and C0 where R covers the complete spatial interval of integration.
Then
function c0 = pdex2ic(r,R,C0)
c0 = interp1(R,C0,r)
end
Note that you will have to pass pdex2ic as @(r)pdex2ic(r,R,C0) to the integrator.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!