MatLab - Raising each component of a matrix

by Aseeb
Tags: component, matlab, matrix, raising
Aseeb is offline
Feb4-13, 09:19 PM
P: 3
I am in great need of the syntax that tells MatLab to raise the component of a vector to any power.

I also need to know the syntax that outputs the time to perform the calculation.

Thank you
Phys.Org News Partner Science news on
Cougars' diverse diet helped them survive the Pleistocene mass extinction
Cyber risks can cause disruption on scale of 2008 crisis, study says
Mantis shrimp stronger than airplanes
jhae2.718 is offline
Feb4-13, 10:14 PM
PF Gold
jhae2.718's Avatar
P: 1,153
If you mean raising the each component of the vector to the same power, e.g. you want ##{\boldsymbol x} ^ n = [x_0^n, x_1^n, \ldots, x_m^n]^T##, then you can use:
% x = some vector
x .^ n;
For timing, you can use:
t = cputime;
% do some operations here
elapsed = cputime - t;
fprintf('Elasped time: %.2f s\n', elapsed);
Aseeb is offline
Feb4-13, 10:32 PM
P: 3
Thank you, Sir.

kreil is offline
Feb5-13, 10:24 AM
kreil's Avatar
P: 518

MatLab - Raising each component of a matrix

For timing, you can also use 'tic' and 'toc' as follows:

X = 1:1000;
X2 = X.^2;

Elapsed time is 0.006004 seconds.
In general, you can put any code snippet between the two tags. 'tic' always marks the beginning of the timer, and 'toc' the end.

Register to reply

Related Discussions
Showing raising operator raising! Advanced Physics Homework 3
Linear Algebra - Raising a matrix to a power Calculus & Beyond Homework 2
Matrix help in MatLab, Not the simple matrix!! I have searched, found nothing! Math & Science Software 3
Raising/Lowering indices and matrix multiplication Special & General Relativity 9
matrix element (raising and lowering operators) Quantum Physics 4