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
How can you plot straight lines in Matlab using only values on x axis and the gradient of each line?
Asked
Active
Viewed 1,513 times
1 Answers
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
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