# Plot graph of polynomials

11 views (last 30 days)
I want to plot graph of polynomial function such as |x| and many more like this.

John D'Errico on 9 Sep 2021
That is not a polynomial.
You have a sqrt root in there. And an absolute value. So learn how to use functions like abs, and sqrt. You will not learn unless you try.
help abs
ABS Absolute value. ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex modulus (magnitude) of the elements of X. See also SIGN, ANGLE, UNWRAP, HYPOT. Documentation for abs doc abs Other functions named abs codistributed/abs duration/abs iddata/abs sym/abs dlarray/abs gpuArray/abs
help sqrt
SQRT Square root. SQRT(X) is the square root of the elements of X. Complex results are produced if X is not positive. See also SQRTM, REALSQRT, HYPOT. Documentation for sqrt doc sqrt Other functions named sqrt codistributed/sqrt dlarray/sqrt gpuArray/sqrt sym/sqrt
First, you would you need to create such a function.
F = @(x) sqrt(abs(x));
Then to plot a function like that, you might read about fplot.
help fplot
FPLOT Plot 2-D function FPLOT(FUN) plots the function FUN between the limits of the current axes, with a default of [-5 5]. FPLOT(FUN,LIMS) plots the function FUN between the x-axis limits specified by LIMS = [XMIN XMAX]. FPLOT(...,'LineSpec') plots with the given line specification. FPLOT(X,Y,LIMS) plots the parameterized curve with coordinates X(T), Y(T) for T between the values specified by LIMS = [TMIN TMAX]. H = FPLOT(...) returns a handle to the function line object created by FPLOT. FPLOT(AX,...) plots into the axes AX instead of the current axes. Examples: fplot(@sin) fplot(@(x) x.^2.*sin(1./x),[-1,1]) fplot(@(x) sin(1./x), [0 0.1]) If your function cannot be evaluated for multiple x values at once, you will get a warning and somewhat reduced speed: f = @(x,n) abs(exp(-1j*x*(0:n-1))*ones(n,1)); fplot(@(x) f(x,10),[0 2*pi]) See also FPLOT3, FSURF, FCONTOUR, FIMPLICIT, PLOT, FUNCTION_HANDLE. Documentation for fplot doc fplot
So you might do this.
fplot(F) Yash Raj Sitaram Prasad on 10 Sep 2021
Thnakyou! It is such a nice support and also presenting some examples!