Creating a diagram from polynomial

1 vue (au cours des 30 derniers jours)
Berkay
Berkay le 30 Août 2022
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 30 Août 2022
Modifié(e) : Walter Roberson le 30 Août 2022
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.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 30 Août 2022
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.

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by