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)
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!