
Creating a diagram from polynomial
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Berkay
am 30 Aug. 2022
Beantwortet: Sulaymon Eshkabilov
am 30 Aug. 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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 30 Aug. 2022
Bearbeitet: Walter Roberson
am 30 Aug. 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.

0 Kommentare
Weitere Antworten (1)
Sulaymon Eshkabilov
am 30 Aug. 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Polynomials finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!