how do I write 2^-x in MatLab?
Mostrar comentarios más antiguos
I need to run a algorithm where 2^(-x) is included.
Respuestas (2)
x=1:10; % if you have x as vector of values
2.^(-x) % then use .^ element wise power
% 2nd option is straightforward
x = 2
2^(-x)
%To insert in a given fnction
x = 1:0.1:10;
func = @(x) exp(x)+2.^(-x)+2*cos(x)
plot(func(x))
x=1;
2^(-x)
1 comentario
John D'Errico
el 17 de Feb. de 2023
Editada: John D'Errico
el 17 de Feb. de 2023
The parens are not technically needed there, but they don't hurt anything.
x = 1;
2^-x
And to be honest, I usually put a parens in something like that myself just to make it easier to read. Sometimes spare parens make things more clear, and sometimes they just create a confusing mess, creating a parenthetical balancing act.
Categorías
Más información sobre Web Services en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
