How do I plot the following graph in Matlab code with same dot lines and continuous line as in the graph? What is the code?
The slant line is the $\eta=2 \xi+1$.
I am a beginner in matlab. Kindly help me with the above drawing
How do I plot the following graph in Matlab code with same dot lines and continuous line as in the graph? What is the code?
The slant line is the $\eta=2 \xi+1$.
I am a beginner in matlab. Kindly help me with the above drawing
On
Here's a way to do it:
\begin{align} & \mathsf {xi=[-2:0.1:5];}\\ &\mathsf{eta1=2*xi+1;}\\ &\mathsf{cnd=(xi<=2); // \text{ Indicator function that's 1 iff xi <= 2, 0 otherwise}}\\ &\mathsf{eta2=cnd.*(2*xi+1) + (1-cnd).*5;}\\ &\mathsf{figure(1);clf;hold\, on;}\\ &\mathsf{plot(xi,eta1, '--');}\\ &\mathsf{plot(xi,eta2, '-');} \end{align}
One possible solution, that also shows my way of working with Matlab.
First, we define $\xi$ varying from $-1$ to $2$ and then compute $\eta_1(\xi)\equiv 2$ and $\eta_2(\xi) = 2\xi+1$.
Now we have to find the intersection. We can do it based on the data, as the first point $\xi$ where $\eta_2(\xi)\ge \eta_1(\xi)$:
Or, if we know that the intersection point is $\xi=0.5$, we can find its index as the index of the last point in the $\xi$-array such that $\xi \le 0.5$:
Now we can divide data into two parts and plot them:
Since Matlab normally uses a new color for a new plot, we manually set colors of second parts equal to the colors of first parts with
Another option is to provide the value of
Coloras an argument of theplotcommand, similar to theLineStyleoption.The resulting figure is