How can i code and solve this PDE on matlab?

Hi! I am looking to solve this PDE on matlab but I am unable to obtain any solution using pdepe function. Would appreciate any assistance!

3 Comments

Please include your code.
I don't see any similarity between your code and the equation you've written.
yes... I tried following the code on mathworks but I can't seems to be able to put my PDE into the code. May I know how should i start with?

Sign in to comment.

Answers (1)

c = 1;
f = alpha2*sqrt(u(1))/(1-u(1))^1.5*DuDx;
s = alpha1*u(1)*(2-u(1))/(1-u(1))^2*DuDx;
u0=?
(You didn't provide a profile at t=0 for epsilon)
pl=?
ql=?
pr=?
qr=?
(You didn't provide boundary conditions for epsilon)

19 Comments

The boundary condition is when z = z0, epsilon = 0.8 and when z = z1, epsilon = 0.2.
When t=0, epsilon(z,0)=0.261.
So,
z0 = 0;
z1 = 1;
u0=0.8*(z==z0)+0.261*(z>z0 & z<z1)+0.2*(z==z1)
and
pl = ur-0.8;
ql = 0;
pr = ur-0.2;
qr = 0;
Does it work ?
Kevin Lee
Kevin Lee on 22 Oct 2018
Edited: Kevin Lee on 22 Oct 2018
matlab returned the following error:
Torsten
Torsten on 22 Oct 2018
Edited: Torsten on 22 Oct 2018
See corrected code. And you neither gave values to alpha1 nor to alpha2.
You didn't define z0 and z1. Further, pdex1ic is a function of x, not z.
Kevin Lee
Kevin Lee on 22 Oct 2018
Edited: Kevin Lee on 22 Oct 2018
It returned the following error:
>> pdex11
Undefined function or variable 'alpha2'.
Error in pdex11>pdex1pde (line 36)
f = alpha2*sqrt(u(1))/(1-u(1))^1.5*DuDx;
Error in pdepe (line 246)
[c,f,s] = feval(pde,xi(1),t(1),U,Ux,varargin{:});
Error in pdex11 (line 17)
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
Am i defining the terms wrongly?
Torsten
Torsten on 22 Oct 2018
Edited: Torsten on 22 Oct 2018
The variables must be accessible where you use them. So the easiest way is to define them in the respective functions. Or include the global statement from above in the function, too.
After i define them in the respective function, matlab returned the following error:
>> pdex11 Error using pdepe (line 293)
Spatial discretization has failed. Discretization supports only parabolic and elliptic equations, with flux term involving spatial derivative.
Error in pdex11 (line 7)
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
Please include your final code as plain text, not as a graphic file.
how do i do so?
By copy-and-paste from the text file in which you develop your code.
I written the code on matlab script directly though
Then save it to a text file.
Kevin Lee
Kevin Lee on 22 Oct 2018
Edited: Kevin Lee on 22 Oct 2018
I have saved the file to a text file but still getting the error on matlab.
>> pdex11 Error using pdepe (line 293)
Spatial discretization has failed. Discretization supports only parabolic and elliptic equations, with flux term involving spatial derivative.
Error in pdex11 (line 7)
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
I meant that you should use the text from the saved text file to include it here.
ah i see! the site say i have reached the limit of 10 uploads. so i have pasted it here below:
function pdex11
m = 0;
x = linspace(0,1,200);
t = linspace(0,600,5);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
% A surface plot is often a good way to study a solution.
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
% --------------------------------------------------------------
function [c,f,s] = pdex1pde(x,t,u,DuDx)
r = 0.01; %radius
V = 4/3*pi*r^3; %volume of sphere
rho = 1000; %density
g = 9.81; %gravity
l = 0.816*r; %length
vis = 1.808*10^-3; %viscosity
ten = 4.189*10^-2; %surface tension
alpha1 = (V*g*rho)/(1999*l*vis);
alpha2 = (ten*sqrt(0.161*V))/(282.7*sqrt(10*l)*vis);
c = 1;
f = alpha2*sqrt(u(1))/(1-u(1))^1.5*DuDx;
s = alpha1*u(1)*(2-u(1))/(1-u(1))^2*DuDx;
% --------------------------------------------------------------
function u0 = pdex1ic(x)
x0 = 0;
x1 = 1;
u0=0.8*(x==x0)+0.261*(x>x0 & x<x1)+0.2*(x==x1);
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ur-0.8;
ql = 0;
pr = ur-0.2;
qr = 0;
Two mistakes I can spot in your code:
1. Define r *before* you calculate V.
2. Use pl = ul-0.8 instead of pl = ur-0.8.
Kevin Lee
Kevin Lee on 22 Oct 2018
Edited: Kevin Lee on 22 Oct 2018
noted on point 2. However, i have already defined r in the line above V.
It returned the following error.
>> pdex11 Warning: Failure at t=1.883061e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (3.552714e-15) at time t. > In ode15s (line 668) In pdepe (line 289) In pdex11 (line 7) Warning: Time integration has failed. Solution is available at requested time points up to t=0.000000e+00. > In pdepe (line 303) In pdex11 (line 7) Error using surf (line 82) Z must be a matrix, not a scalar or vector.
Error in pdex11 (line 12) surf(x,t,u)
The code is technically ok now.
Since I don't know about the background of your problem, I can't help you any longer.

Sign in to comment.

Asked:

on 22 Oct 2018

Commented:

on 22 Oct 2018

Community Treasure Hunt

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

Start Hunting!