plotting a supply and demand curve in matlab

To plot supply and demand curves in Matlab, you can use the following steps:

main.m
        1. Define arrays for the quantity supplied and demanded at different prices:

        ```
        prices = 1:10;
        quantity_supplied = 2*prices.^2;
        quantity_demanded = 100 - 3*prices;
        ```

        Here, we assume that the supply curve is given by `quantity_supplied = 2*prices^2`, and the demand curve by `quantity_demanded = 100 - 3*prices`.

        2. Plot the supply and demand curves using `plot` function:

        ```
        plot(prices, quantity_supplied, 'b-', 'LineWidth', 2);
        hold on;
        plot(prices, quantity_demanded, 'r--', 'LineWidth', 2);
        ```

        Here, we plot the supply curve in blue color with solid line `b-`, and the demand curve in red color with dashed line `r--`.

        3. Add labels and title to the plot using `xlabel`, `ylabel`, and `title` functions:

        ```
        xlabel('Price');
        ylabel('Quantity');
        title('Supply and Demand Curves');
        ```

        This will add x-axis label "Price", y-axis label "Quantity" and a title "Supply and Demand Curves" to the plot.

        4. Add legend to the plot using `legend` function:

        ```
        legend('Supply', 'Demand');
        ```

        This will add a legend to the plot showing the labels "Supply" and "Demand" for the corresponding curves.

        Here's the complete code:

        ```
        prices = 1:10;
        quantity_supplied = 2*prices.^2;
        quantity_demanded = 100 - 3*prices;

        plot(prices, quantity_supplied, 'b-', 'LineWidth', 2);
        hold on;
        plot(prices, quantity_demanded, 'r--', 'LineWidth', 2);
        xlabel('Price');
        ylabel('Quantity');
        title('Supply and Demand Curves');
        legend('Supply', 'Demand');
        ```

        This will produce a plot showing the supply and demand curves intersecting at the equilibrium price and quantity.
1885 chars
56 lines

gistlibby LogSnag