Algorithm for Fractional power calculation
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
1. fractional base is no problem with current implementation.
2. To support fractional exponents, get the n-th root for any given number b. How to implement algorithm to get a numerical approximation ?
3. Current approach is inefficient, because it loops e times
b = [-32:32]; % example input values
e = [-3:3]; % example input values but doesn't support fraction's
power_function(b,e)
p = 1;
if e < 0
e = abs(e);
multiplier = 1/b;
else
multiplier = b;
end
for k = 1:e
p(:) = p * multiplier; % n-th root for any given number
end
0 comentarios
Respuestas (1)
Alan Stevens
el 28 de Feb. de 2022
How about using the Newton-Raphson algorithm. Here's the basic idea:
% x^n = b
% Let f(x) = x^n - b
% dfdx(x) = n*x^(n-1)
%
% Use Newton-Raphson iteration
% x1 = initial guess
% err = 1;
% while err > tol
% x = x1 - f(x1)/dfdx(x1);
% err = abs(x - x1);
% x1 = x
% end
13 comentarios
Life is Wonderful
el 12 de Mzo. de 2022
Editada: Life is Wonderful
el 13 de Mzo. de 2022
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!