Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I assume that you are not using symbolic variables. For 2D plotting in matlab you need two equal size vectors, one per axis, so you need to create a x-axis vector and y-axis vector. In your example f(x) = 1- |x| for |x| &lt; 1 you could do this:</p> <pre><code>x = linspace(-5,5,500); %x-axis vector from -5 to 5 with 500 points y = zeros(1,500); %y-axis vector initialized to 0, also 500 points like the x-axis vector y(abs(x) &lt; 1) = 1- abs(x(abs(x)&lt;1)); %the points corresponding to |x|&lt; 1 are set to |x| figure() %new figure plot(x,y) %plot box off %removing box grid on %adding grid xlabel('x axis', 'FontSize', 15) %label of x axis ylabel('y axis', 'FontSize', 15) %label of y axis axis([x(1), x(end), -0.5, 1.5]) %axis limits </code></pre> <p>With that you get a plot like this one:</p> <p><img src="https://i.stack.imgur.com/GCH4D.jpg" alt="enter image description here"></p> <p>For the other functions you have to proceed like in this one, build the x-axis vector and the y-axis vector.</p> <p><strong>UPDATE:</strong> In the other example: <code>f(x) = A for x &gt;= 0 and f(x) = 0 for x &lt; 0</code>:</p> <pre><code>A = 3; x = linspace(-5,5,500); %x-axis vector from -5 to 5 with 500 points y = zeros(1,500); %y-axis vector initialized to 0, also 500 points like the x-axis vector y(x &gt;= 0) = A; %the points corresponding to x &gt;= 0 are set to A figure() %new figure plot(x,y) %plot box off %removing box grid on %adding grid xlabel('x axis', 'FontSize', 15) %label of x axis ylabel('y axis', 'FontSize', 15) %label of y axis axis([x(1), x(end), -0.5, 3.5]) %axis limits </code></pre> <p><img src="https://i.stack.imgur.com/bgLeF.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload