Roots of a 4th degree polynomial and plotting a graph

13 vues (au cours des 30 derniers jours)
Yuvraaj Pasumarthy
Yuvraaj Pasumarthy le 27 Jan 2024
Modifié(e) : John D'Errico le 27 Jan 2024
I have a 4th degree polynomial which has a variable, say k for one of its coefficients, how can I find roots (r) for this equation while describing that variable within a range of values
Is it possible to plot a graph using these values of the roots 'r' and the corresponding values of 'k'

Réponses (3)

Dyuman Joshi
Dyuman Joshi le 27 Jan 2024
Modifié(e) : Dyuman Joshi le 27 Jan 2024
Define the polynomial as a Function Handle of the variable 'k' and use roots for different values of 'k'.
Yes, you can plot the values of roots but note that if the equation has complex roots, the complex parts will be ignored if you use plot() directly.
In that case, you can plot the real and imaginary values separately.
  2 commentaires
Yuvraaj Pasumarthy
Yuvraaj Pasumarthy le 27 Jan 2024
is it possible to get a sample code for this? I have not used function handle before
Torsten
Torsten le 27 Jan 2024
In this case, I suggest you first take a 2-hours introductory course free of cost to learn the basics of MATLAB:

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 27 Jan 2024
Modifié(e) : Image Analyst le 27 Jan 2024
Not for some arbitrary k, unless there is something in the symbolic toolbox you can use. Otherwise put k in with the other coefficients and call roots and then plot for example
k = -5;
% For coefficients [1,2,k,3,-1500]
% y = 1*x.^4 + 2 * x.^3 + k*x.^2 + 3*x.^1 + 1500
coefficients = [1,2,k,3,-1500];
theRoots = roots(coefficients)
theRoots =
-7.0501 + 0.0000i 5.9345 + 0.0000i -0.4422 + 5.9713i -0.4422 - 5.9713i
x = linspace(-8.3, 7, 512);
y = 1*x.^4 + 2 * x.^3 + k*x.^2 + 3*x.^1 - 1500;
plot(x, y, 'LineWidth', 2)
grid on
xlabel('x');
ylabel('y');
caption = sprintf('Plot for k = %f', k);
title(caption);
yline(0, 'r-') % Red line along y=0 axis.
% Plot any purely real roots as red circles on the y axis.
for k = 1 : numel(theRoots)
if imag(theRoots(k)) == 0
hold on
plot(theRoots(k), 0, 'ro', 'LineWidth', 2)
end
end

John D'Errico
John D'Errico le 27 Jan 2024
Modifié(e) : John D'Errico le 27 Jan 2024
Effectively, you are telling us that one of the coefficients of the polynomial is determined to within some interval. And now you want to characterize how the roots will behave, as a function of that parameter. I might call this a problem of interval arithmetic. But the thing is, those roots will (sometimes) be highly nonlinear functions of that parameter. And sometimes, the roots might be well-behaved, not at all that nonlinear. I would suggest the first case is more likely however, especially for a degree 4 polynomial.
No, there is no simple code to do what you ask. And there is nothing in the symbolic toolbox that can solve the problem. You will also need to deal with things like bifurcations, etc.
What can you do? Well, the simple thing would be to generate the roots for many values of k. Then combine the roots into one array, and call plot, plotting them as a function of k. An issue here is the roots will often change order. They do not get returned from a tool like roots in any meaningful order. And that means your plot will sometimes appear non-sensical. One solution to that is to convert the polynomial function into its companion matrix form, then use a tool like my eigenshuffle, as found on the file exchange. It will actively attempt to resequence the roots it finds.
Sigh. I'm sorry. But a problem like this is not something with a trivial solution. And if you have no clue even what a function handle is, you need to spend some time learning MATLAB first. Start with the tutorials as suggested.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by