Plotting polynomial values at given points.

3 views (last 30 days)
Beaya
Beaya on 6 Nov 2013
Moved: Mathieu NOE on 15 Jun 2023
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)

Answers (1)

pragnan nadimatla
pragnan nadimatla on 15 Jun 2023
Moved: Mathieu NOE on 15 Jun 2023
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!

Categories

Find more on Polynomials in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!