I just started to learn simulation about PDEs and encountered difficulties. How can I use method-of-lines to solve the following three variables and draw a graph?

13 Comments

Hi @Yidan,
Could you please write these equations in text format, so they are legible enough to implement in Matlab. For example, I don’t know if you wrote dt or alpha with subscript t or Beta or B etc
Thanks for your suggestion, I have changed the question.
What problems do you encounter to modify the solution I gave you for a 2-component system to a 3-component system ?
If you have problems using MATLAB, try MATLAB Onramp for an introduction to MATLAB free-of-costs to learn the basics of the language:
If you have problems with the numerics of hyperbolic equations, consult a textbook.
Another option is to use the trick suggested by Bill Greene to make "pdepe" work for your problem. Using "pdepe" for hyperbolic systems is problematic because one of the boundary conditions has to be artificially set and often, the computed solution shows some oscillations because the discretization scheme is not adequate. But the general trend should be ok.
Thank you very much for your reply again! !!
After the first question, I learned the method called method of lines and used pdepe again according to Bill Greene suggestion.
(1) In this problem with three variables, since f(x,t,u,∂ux)=0 is set, the value of q(x,t) does not affect the result according to theory, but I found that different values of q(x,t) have a great impact on the result, so I asked again.
The code about this question(picture) is :
function [c,f,s] = pdefun(x,t,u,dudx) % Equation to solve
c = [1; 1; 1];
f = [0; 0; 0];
s = [-0.6; 1.32; 10].*dudx+[-1; -1; 0].*u;
end
function u0 = pdeic(x) % Initial Conditions
u0 = [sin(pi*x); sin(pi*x) ; 0];
end
function [pl,ql,pr,qr] = pdebc(xl,ul,xr,ur,t) % Boundary Conditions
pl = [2.2*ul(2)+ ul(1); 0; 0];
ql = [0; 1; 1];
pr = [-ur(2)+0.19*ur(1)+ul(3); 0; ur(3)];
qr = [0; 1; 1];
end
x = linspace(0,1,100);
t = linspace(0,1,30);
m = 0;
sol = pdepe(m,@pdefun,@pdeic,@pdebc,x,t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);
u3 = sol(:,:,3);
surf(x,t,u1)
title('u_(x,t)')
xlabel('Distance x')
ylabel('Time t')
If you choose different q, the result changes. I don't whether i made some mistakes.
(For example, if ql = [0; 1; 1];qr = [1; 1; 1]; The sesult changes)
(2) And I tried to use the method of lines on this three variables, and the error was the problem of array index. I think I haven't fully understood it yet, but it is difficult to find materials to study and code analysis, so I want to learn and understand by comparing the codes of different variables.
I sincerely thank you for your detailed answer.
p must be set to 0 and q must be set to 1 (or any other value) for those equations and boundary points for which you don't have a boundary condition - thus for alpha at x = 1 and for beta and Z at x = 0. p must be set to the value and q must be set to 0 for those equations and boundary points for which you have a boundary condition - thus for alpha at x = 0 and for beta and Z at x = 1. So can you spot your mistakes in the boundary function ?
I think may be the boundary condition is :
pl = [2.2*ul(2)+ ul(1); 0; 0];
ql = [0; 1; 1];
pr = [-ur(2)+0.19*ur(1)+ul(3); 0; ur(3)];
qr = [0; 1; 0];
but if I change it as:
pl = [2.2*ul(2)+ ul(1); 0; 0];
ql = [0; 1; 1];
pr = [-ur(2)+0.19*ur(1)+ul(3); ur(3); 0];
qr = [0; 0; 1];
it doesn't work, why?
Both solutions are wrong.
pl(1) = 2.2*ul(2)+ ul(1),
ql(1) = 0,
pr(1) = -ur(2)+0.19*ur(1)+ul(3),
qr(1) = 0
means that you set boundary conditions for alpha at x = 0 as well as at x = 1.
But this is not correct. You can only set a boundary condition for alpha at x = 0.
Sorry, but this is really a level of logic you should understand by yourself from what I said:
p must be set to 0 and q must be set to 1 (or any other value) for those equations and boundary points for which you don't have a boundary condition - thus for alpha at x = 1 and for beta and Z at x = 0.
p must be set to the value and q must be set to 0 for those equations and boundary points for which you have a boundary condition - thus for alpha at x = 0 and for beta and Z at x = 1.
Thanks.
I rethought my thoughts and I think it should be like this:
pl = [2.2*ul(2)+ ul(1); 0; 0];
ql = [0; 1; 1];
pr = [0; -ur(2)+0.19*ur(1)+ul(3); ur(3)];
qr = [1; 0; 0];
Thanks!!!
This is my first time to learn how to use Matlab to simulate PDE. I sincerely thank you for your guidance.
Next, I will learn how to use the method of lines to simulate.

Sign in to comment.

Answers (0)

Products

Asked:

on 21 Aug 2024

Commented:

on 21 Aug 2024

Community Treasure Hunt

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

Start Hunting!