How can you plot straight lines in Matlab using only values on x axis and the gradient of each line?

1.5k Views Asked by At

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

1

There are 1 best solutions below

0
On

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.