**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# 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?

4 views (last 30 days)

Show older comments

##### 13 Comments

Umar
on 21 Aug 2024

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
on 21 Aug 2024

Edited: Torsten
on 21 Aug 2024

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
on 21 Aug 2024

Edited: Yidan
on 21 Aug 2024

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
on 21 Aug 2024

Edited: Torsten
on 21 Aug 2024

Yidan
on 21 Aug 2024

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
on 21 Aug 2024

Edited: Torsten
on 21 Aug 2024

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
on 21 Aug 2024

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
on 21 Aug 2024

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
on 21 Aug 2024

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.

### Answers (0)

### See Also

### Categories

### Products

### Community Treasure Hunt

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

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

- América Latina (Español)
- Canada (English)
- United States (English)

Europe

- 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)

Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)