How vectorize this operation

1 Ansicht (letzte 30 Tage)
Iori Yagami Kusanagi
Iori Yagami Kusanagi am 8 Okt. 2018
Bearbeitet: Bruno Luong am 9 Okt. 2018
Can someone help me please?
x = 10*ones((10^7),1);
L = ((length(x)*2):-2:2)';
M = x.*L;
p= -M./L;
c= 0.25;
x = x+c*p;
Is possible vectorize x = x+c*p;
  5 Kommentare
Iori Yagami Kusanagi
Iori Yagami Kusanagi am 8 Okt. 2018
Yes, is a optimization problem that I need to solve, and when run on that part take a lot of time
Bruno Luong
Bruno Luong am 9 Okt. 2018
Bearbeitet: Bruno Luong am 9 Okt. 2018
You know how much memory has your PC? Usually few or few dozen Gb. How you intend to carry out the storage of such matrix on the computer?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 9 Okt. 2018
The code works vectorized already. So the problem is not vectorizing.
The code can be simplified slightly:
M = x .* L;
p = -x; % instead of: -M ./ L, but p is not needed at all
c = 0.25;
x = (1-c) * x; % instead of: x + c * p;
The code is not meaningful yet. Maybe there is another way to improve it. But again, vectorization is applied here already.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by