plot a quadratic in matlab

Suppose we have a quadratic equation y = ax^2 + bx + c, we can plot this curve in MATLAB using the following steps:

  1. Define the quadratic equation coefficients a, b, and c.
  2. Define the range of x values.
  3. Calculate the corresponding y values for each x value using the quadratic equation.
  4. Plot the calculated values of x versus y using the plot function.

Here is an example code snippet:

main.m
a = 1;
b = 2;
c = 1;

x = -10:0.1:10;
y = a*x.^2 + b*x + c;

plot(x, y)
72 chars
9 lines

This will plot a simple quadratic with a minimum value at x = -b/2a and a y value of c-b^2/4a. You can adjust the range of x values and the coefficients to plot any quadratic you want.

related categories

gistlibby LogSnag