How to solve quadratic equations of nonscalar constants?
1 次查看(过去 30 天)
显示 更早的评论
Hi guys, I have another question. So I simply want to solve a quadratic equations, well MATLAB has roots function to find the solutions.
pol = [A B C];
sol = roots(pol);
which will give you the roots of Ax^2+Bx+C = 0. However in my problem all A, B, and C are matrix of the same size, and I want to get the largest root from each set of the polynomial constant comprising the elements of the same index from A, B, and C. Which means in the end I will get a matrix with the same size of either A, B, or C containing the largest roots from each set of equation. I can do this by using 'for' loop
for i = 1:size(A,1)
for j = 1:size(A,2)
pol = [A(i,j) B(i,j) C(i,j)];
root = max(roots(pol));
end
end
But this takes tremendous amount of time since the size of matrices A and the other is very big. I'm not sure if using another solver function like fzero will cut the execution time a lot. And simply using the familiar formula for solving quadratic equations is not favorable either because there are some zero elements in matrix A. So is there a way to solve this problem without using 'for', and give reasonable speed?
I will really appreciate your help.
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!