Plotting polynomial values at given points.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)
0 commentaires
Réponses (1)
pragnan nadimatla
le 15 Juin 2023
Déplacé(e) : Mathieu NOE
le 15 Juin 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!
0 commentaires
Voir également
Catégories
En savoir plus sur Polynomials dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!