





% Example data U = 1; Bx = [1.5; 2.0; 2.5]; % Column vector B = [1.1; 1.2; 1.3]; % Column vector
% Define quadratic coefficients: c2*a^2 + c1*a + c0 = 0 c2 = B.^2; c1 = -3 * U * Bx; c0 = 2 * U^2;
% Solving for r for each row r_results = zeros(length(B), 2); % Preallocate for two possible roots
for i = 1:length(B) % Find roots of the quadratic for a (which is r^3) a_roots = roots([c2(i), c1(i), c0(i)]);
% Convert back to r
r_results(i, :) = a_roots.^(1/3);
end
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!