MATLAB Answers

Plot graph of polynomials

조회 수: 7(최근 30일)
I want to plot graph of polynomial function such as |x| and many more like this.

채택된 답변

John D'Errico
John D'Errico 2021년 9월 9일
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)

추가 답변(1개)

Yash Raj Sitaram Prasad
Yash Raj Sitaram Prasad 2021년 9월 10일
Thnakyou! It is such a nice support and also presenting some examples!

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by