Creating a diagram from polynomial

조회 수: 1 (최근 30일)
Berkay
Berkay 2022년 8월 30일
답변: Sulaymon Eshkabilov 2022년 8월 30일
I defined a polynomial
P = [1 -2 4]
and I want to draw the shape of polynomial for the range between -10 to 10 with in the logarithmic diagram (only X axis). How can I do it?

채택된 답변

Walter Roberson
Walter Roberson 2022년 8월 30일
편집: Walter Roberson 2022년 8월 30일
P = [1 -2 4];
x = linspace(-10, 10, 500);
y = polyval(P, x);
lx = log10(x);
rlx = real(lx);
ilx = imag(lx);
plot3(rlx, ilx, y)
xlabel('real(log(x))'); ylabel('imag(log(x))'); zlabel('polynomial value')
You need to use a 3D plot for this because you want a log axes on a range that includes negative values, so you need some way to represent the component of the log of the negative numbers.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 8월 30일
There are a few different ways to get this exercise done.
Compute the values of the polynomial P = [1 -2 4] at x = -10:dx:10 with some increment step size (dx) and then plot x vs. y using semilogx(). The code starts with these:
P = [1 -2 4];
dx = ...
x= -10:dx:10;
y = P(1)*x.^2+P(2)*x+P(3);
figure()
...
If you have a difficulty to undertand how to plot the computed values, use help.
>> help semilogx
Moreover, your plotted data will contain the positive values of x and the negative side will be ignored due to a log scale.

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by