Creating a diagram from polynomial

1 次查看(过去 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
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