main.m553 chars22 lines
This code will create five random polynomials of degree 1, 2, 3, 4, 5 and plot them on the same figure in Matlab. The degrees
variable defines the degree values for each of the polynomials. The rand
function is used to generate random coefficients for each polynomial, and polyval
is used to evaluate the polynomial at each x value. The fplot
function is used to plot the polynomial for the range [-1, 1]. The title
, xlabel
, and ylabel
functions are used to add labels to the figure, and the legend
function is used to create a legend for each degree of polynomial. Finally, hold on
is used so that all the polynomials are plotted on the same figure.
gistlibby LogSnag