Plotting polynomial values at given points.

3 次查看(过去 30 天)
I want to find the roots of Wilkinson polynomial and then compute the values of this polynomial for these roots. Everytning goes fine until I try to plot the values for my roots. I get: "Error using plot. Vectors must be the same lengths" How can I fix it? This what I wrote:
syms x;
P20 = prod(x-(1:n));
P = expand(P20);
z = roots(p);
y = poly (z);
fmt = '%25.16f\n';
fprintf(fmt,z),
plot (z,y)

回答(1 个)

pragnan nadimatla
pragnan nadimatla 2023-6-15
移动:Mathieu NOE 2023-6-15
As per my understanding,you are encountering an error while trying to plot the roots of Wilkinson polynomial.In this case,the potential cause behind the error is that you are not specifying the X-Values for the polynomial.
Please refer below for the corrected version of code.
syms x;
n = 20;
P20 = prod(x-(1:n));
P = expand(P20);
z = roots(P);
fmt = '%25.16f\n';
fprintf(fmt,z);
% Evaluate the polynomial at 1000 points between -1.5 and 1.5
x_vals = linspace(-1.5, 1.5, 1000);
y_vals = subs(P, x_vals);
% Plot the polynomial and the roots
figure;
plot(x_vals, y_vals);
I hope the provided resolution helps!

类别

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