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

Stephen23
Stephen23 2018년 10월 8일
편집: Stephen23 2018년 10월 8일
What does "Is possible vectorize x = x+c*p" mean? That line of code already operates on vectors (of appropriate sizes) and does not throw an error. What are you trying to achieve?
Iori Yagami Kusanagi
Iori Yagami Kusanagi 2018년 10월 8일
When I change the value of c, implementing linear search, takes a lot of time this procedure.
Bruno Luong
Bruno Luong 2018년 10월 8일
편집: Bruno Luong 2018년 10월 8일
Are you awared that you creates arrays of few hundred of Tb?
Iori Yagami Kusanagi
Iori Yagami Kusanagi 2018년 10월 8일
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 2018년 10월 9일
편집: Bruno Luong 2018년 10월 9일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 10월 9일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

태그

질문:

2018년 10월 8일

편집:

2018년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by