0

I want to be able to simulate a hyperbolic equation on characteristic curves (lines). I will start with a basic one. u_{t}+2u_{x}=u^{2} with initial data u(x,0)=cos(x). The solution is u(x,t)=cos(x-2t)/(1-t*cos(x-2t)) where the charackteristic curve is x=2*t+x_{0}. So the solution is defined on characteristics (method of characteristics).

x=zeros(10,5);
u=zeros(10,5);
x0=linspace(0,10,10);
t=linspace(0,5,5);
for i=1:length(x0)
    for j=1:length(t)
        x(i,j)=2*t(j)+x0(i);
        if t(j)*cos(x(i,j)-2*t(j))==1
            u(i,j)=0;
        else
            u(i,j)=cos(x(i,j)-2*t(j))/(1-t(j)*cos(x(i,j)-2*t(j)));
        end
    end
end
mesh(u)

Apperently, the grid of characteristic lines and rectangular grid do not fit eachother. How can I plot the solutions on characteristics?

Chimera
  • 5,884
  • 7
  • 49
  • 81
user1018331
  • 143
  • 4
  • 14

1 Answers1

1

Firstly, you do not have a rectangular grid due to this line

x(i,j)=2*t(j)+x0(i);

I am not entirely sure what you are asking. I get the impression that you might want to plot the surface of u over the irregular mesh x. If this is indeed the case, you may find the following like enables you to do what you need - although it does look like you will need to do some tweaking of your code.

http://blogs.mathworks.com/videos/2007/11/02/advanced-matlab-surface-plot-of-nonuniform-data/

Alternatively, you could just redesign your code such that x results in a rectangular grid - I cannot say for sure as maybe there is a reason that you only consider these particular points.

If you get no better answers, the above link could enable you to get what you want (assuming I have understood your question correctly).

mathematician1975
  • 21,161
  • 6
  • 59
  • 101