To plot the functions x, x^2, x^3, x^4, and x^5 across the interval [0, 1] in MATLAB, you can follow the steps below:
x
with values from 0 to 1 using the linspace
function:main.m20 chars2 lines
y1 = x
, y2 = x.^2
, y3 = x.^3
, y4 = x.^4
, and y5 = x.^5
:main.m52 chars6 lines
figure
function:main.m8 chars2 lines
plot
function:main.m41 chars2 lines
legend
function:main.m41 chars2 lines
xlabel
and ylabel
functions:main.m26 chars3 lines
title
function:main.m44 chars2 lines
Putting it all together, here's the complete MATLAB script:
main.m232 chars13 lines
Running this script will display a single figure window with the plot of the functions x, x^2, x^3, x^4, and x^5 across the interval [0, 1].
Note: The ^
operator is used for element-wise exponentiation in MATLAB.
gistlibby LogSnag