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?
59 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1756884/image.jpeg)
13 个评论
Umar
2024-8-21,5:09
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
Torsten
2024-8-21,9:36
编辑:Torsten
2024-8-21,9:49
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.
Yidan
2024-8-21,10:07
编辑:Yidan
2024-8-21,10:09
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,∂u∂x)=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.
Torsten
2024-8-21,11:44
编辑:Torsten
2024-8-21,12:16
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 ?
Yidan
2024-8-21,12:16
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?
Torsten
2024-8-21,12:24
编辑:Torsten
2024-8-21,12:30
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.
Torsten
2024-8-21,12:35
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.
Yidan
2024-8-21,12:42
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];
Yidan
2024-8-21,12:50
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Eigenvalue Problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)