Double for Loop to find root of polynomial

2 views (last 30 days)
Hi,
I'm trying to code a double for loop for the variables M and L, allowing me to find the roots of the polynomial at each point for 0<M, L<1. I'm very new to MATLAB and can't really get anything useful.
Thanks.

Accepted Answer

John D'Errico
John D'Errico on 30 Oct 2019
lambda=2;
Quadratic_For_Omega_Squared=@(L,M)[1,-(L^2 +2 * M^2 +1 -lambda), +M^2 * (L^2 +M^2 -lambda)];
L=1:-0.1:0;
M=1:-0.1:0;
R = zeros(numel(L),numel(M),2);
for k1 = 1:numel(L);
for k2 = 1:numel(M);
p = Quadratic_For_Omega_Squared(L(k1),M(k2));
R(k1,k2,:) = roots(p);
end
end
  1 Comment
Alexander Kimbley
Alexander Kimbley on 31 Oct 2019
Thanks,
is there anyway I could extend this question for the code to present a graph in (L,M) space where each point is a certain colour depending on how many roots at that point are postive, i.e. 0,1 or 2.
Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!