0

I'm trying to plot characteristics for the Burgers Equations. But I have to plot them only using the inbuilt function plot. It seems like a fairly straight forward problem but I still cant solve it

  • Hint: how do would you plot those lines on paper? Remember that all Matlab requires to plot a line are two points on the line itself... – A.P. Mar 19 '15 at 11:00
  • I have the gradients for each spatial point. I have a sin^2(pi*x) initial condition and 0 for the other over an interval. Hence, I have some lines which should have infinite gradient, which is straight forward but I'm still uncertain how to obtain other points on lines with gradient such as 1.12. I know I will be able to do linear interpolation. Is this difficult to implement via Matlab?

    dx=0.01; dt=dx;

    X=2; x=0:dx:X;

    Tf=1;

    n=floor(X/dx); n1=floor(1/dx);

    timesteps=floor(Tf/dt);

    u1=sin(pix).sin(pi*x); u11=u1(1:n1); u2=zeros(1,n1+1);

    u0=[u11,u2]; u=u0;

    c=1./u0;%gradients

    – f_olivere Mar 19 '15 at 14:35
  • If you want any real help with your Matlab code you'd better write the whole code properly and then ask exactly what you need. You do not explain the mathematical problem and it is not really clear what you want the matlab program to do. – Beni Bogosel Nov 15 '15 at 00:07

1 Answers1

1

I've got no idea of what the Burgers Equations are, so I'm going to answer the question in the title.

Suppose you have a point $(a,0)$ on the $x$-axis and you want to plot a line in $\mathbb{R}^2$ through that point, with slope (gradient) $m$. This line has Cartesian equation $y = m(x-a)$. So, suppose you want to use the plot function to plot lines $l_1,\dotsc,l_n$ for $x \in [x_1,x_2]$. Further, suppose the abscissa of the basepoints are stored in a vector a and that the slopes are stored in a vector m (both of length $n$, of course). Then

X = [x1,x2];

for i = 1:n
  f = @(x) m(i)*(x-a(i));
  Y(i,:) = f(X);
end
plot(X,Y)

should do. Here @(x) allows you to define an anonymous function in the variable x.

A.P.
  • 9,906