How can the pdepe solver solution be used as a new initial condition for the next iteration? i.e using pdepe within a loop
조회 수: 11(최근 30일)
표시 이전 댓글
I solved the convection diffusion equation using pdepe solver.
I would like to solve this equation within a loop. i.e
the output solution at the tout is a vector, which should be used as new initial condition.
It would be appreciated to help in this issue.
댓글 수: 0
답변(1개)
Venkatachala Sarma
2016년 1월 12일
편집: Venkatachala Sarma
2016년 1월 12일
Hi Younus,
This could be done by using a variable shared between the function calling 'pdepe' and the function pdex1ic(x) which gets called to manage the initial conditions. Let us take a global variable as an example.
Consider the first example in the following documentation page.
In this example, you could declare a global variable which will be updated with the solution of 'pdepe' every time it runs. Just equate this global variable to the output of the function pdex1ic which manages the initial condition.
I am pasting the modified version of pdex1 and pdex1ic functions alone. Remaining of the example code is retained.
if true
function pdex1
global takeOut;
m = 0;
x = linspace(0,1,20);
t = linspace(0,2,5);
takeOut = 0;
for i = 1:5
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
u = sol(:,:,1);
takeOut = u(end,end);
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
end
end
end
The above function puts the pdepe function in a loop and uses the global variable named takeOut to carry the current solution. This is just to show an example and you can explore the other possibilities. The pdex1ic function shown below just copies the value in this variable.
if true
function u0 = pdex1ic(x)
global takeOut;
u0 = takeOut;
end
end
Update these functions in the example and run it. You could see that the outputs vary depending upon the initial conditions.
Hope this helps.
Regards Venkatachala Sarma
댓글 수: 4
Haonian Shu
2020년 4월 20일
Dear Antonio,
I am have the same issue and have been trying to follow your solution. Yet I cannot figure out where should I declare the solution u1, since u1 is not global, how can it be extracted by the ic function. also, I am struggling to understand the goal of this initail condition function, the goal of xcopy. actually, all i want to find is to give pdepe a custumized, discrete (arbitrary) initial condition rather than a number or a simple analytical function.
Best
참고 항목
범주
Find more on Partial Differential Equation Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!