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?
0 件のコメント
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Object Properties についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!