Plotting polynomial values at given points.

3 visualizzazioni (ultimi 30 giorni)
Beaya
Beaya il 6 Nov 2013
Spostato: Mathieu NOE il 15 Giu 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)

Risposte (1)

pragnan nadimatla
pragnan nadimatla il 15 Giu 2023
Spostato: Mathieu NOE il 15 Giu 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!

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by