MATLAB Answers

I'm plotting a solution to a PDE using surf but the graph turns out wrong?

조회 수: 1(최근 30일)
Vicky Ngo
Vicky Ngo 2021년 6월 10일
편집: John D'Errico 2021년 6월 10일
I'm trying to plot the solution to a PDE, which is an infinite series:
So far this is my code, I can't see what's wrong with it. I've attached the graph i got below.
edit: the sin part is part of the summation, and the original pde is:
xRange = 0:0.1:6;
tRange = 0:0.1:6;
[x,t] = meshgrid(xRange,tRange);
u = zeros(size(x));
for n=1:300
u = u+(4/(n^3*pi^3)+(4/(n*pi)-4/(n^3*pi^3))*exp(-n^2*pi^2.*t)).*sin(n*pi/2*x);
end
surf(x,t,u);
xlabel("X");
ylabel("T");
zlabel("U");

채택된 답변

John D'Errico
John D'Errico 2021년 6월 10일
편집: John D'Errico 2021년 6월 10일
Do you understand that the series you show is not the same as what you wrote in code?
Where did the sin term go in your code? Without it, you get something VERY different.
Edit:
ARGH. We seem to be chasing a moving problem.
Along at least one edge, you have a problem that the series is poorly convergent, and taking only 10 terms is inadequate. You would need many more terms in the series, when t==0. In fact, as I look, your series, it is divergent when t == 0. Why is that the case? When t == 0, the exponential goes away. So now you have an infinite sum of the terms
4/(n*pi)
And since this sub-series is divergent, you have a problem along that edge.
  댓글 수: 2
John D'Errico
John D'Errico 2021년 6월 10일
And I just updated my answer. Again, THINK about how that series reduces, when t == 0, or even when t is small. For small t, the series will be VERY slowly convergent. When t == 0, the series is divergent. And that means you get garbge when t == 0. Even for small t, taking only 10 terms is rediculously inadequate.
So again, substitute t == 0 into that series. DO IT NOW! Look at what you see. Do you see the sum from 1 to infinity of 4/pi*(1/n) as a subseries?
Do you understand that this series is divergent, that it becomes infinitely large? In mathematics, this is called the Harmonic series. Read here:
Do you see that it is divergent? And that means, when t = 0, or even for small t, you will get complete and utter garbage in your plots.
If you don't believe me, LOOK AT THE PLOT YOU PRODUCED. Do you see that in your plot? Look at the edge where t == 0. Even when t is small, you see strange stuff. That happens because when t is small, the result will be slowly convergent. When t is zero, it will be divergent.

댓글을 달려면 로그인하십시오.

추가 답변(2개)

Max Heiken
Max Heiken 2021년 6월 10일
편집: Max Heiken 2021년 6월 10일
The part with the sin is missing in your code.
for n=1:10
u = u+(4/(n^3*pi^3)+(4/(n*pi)-4/(n^3*pi^3))*exp(-n^2*pi^2*t)).*sin(n*pi*x/2);
end
surf(x,t,u);
edited: It seems like the sin part is supposed to be part of the summation.
  댓글 수: 1
Vicky Ngo
Vicky Ngo 2021년 6월 10일
Sorry about that, I just realized and changed my code (and updated this question). However the graph still doesn't look right...

댓글을 달려면 로그인하십시오.


KSSV
KSSV 2021년 6월 10일
MAy be you are looking for this:
n=1:10 ;
tRange = 0:0.05:1;
[n,t] = meshgrid(n,tRange);
u = (4./(n.^3*pi^3)+(4./(n*pi)-4./(n.^3*pi^3)).*exp(-n.^2*pi^2.*t));
surf(n,t,u);
xlabel("X");
ylabel("T");
zlabel("U");
  댓글 수: 1
Vicky Ngo
Vicky Ngo 2021년 6월 10일
I tried, but most of the graph is flat except for the edges, which I think is rather weird...

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by