Reducing the size of the problem for a sparse matrix function.
3 views (last 30 days)
Show older comments
I have a code that runs out of memory on a 3 gb desktop. I want to make the code suitable so that it runs on any desktop wih ram atleast 3gb. I am providing the code below, can anyone please help with it?
Also how can i reduce the scale, i mean if this is 1:1, then how can i reduce it 1:10?
Code:
function [I,A,P,Q,O]= optim1(Y_s, sigma_s, delta_x, delta_y, b, s, d, R, H)
the inputs are y_s=25.89*10^3, Sigma_s= 2.97 delta_x=delta_y=3 b=7 s=d=4 R=H=10^7
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%determing the value of the objective function by the variable dwell time
%appraoch.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input Parameters :
%for a 3-D hemispherical shape to be machined,
% R = radius of the 3-D hemisphere
% H = total hieght of the block given
% delta x = delta y = pixel size
%b = beam width diameter (nm)
%s = lenght of cube in x direction (micro m)
%d = length in y direction (micro m)
% Output :
% a 1600 x 1 column matrix comprising of the values of the objective
% function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Model Parameters :
n = floor((d*10^3)/delta_x);
m = floor((s*10^3)/delta_y);
%o = floor(b/sigma_s);
o=ceil(3*sigma_s/delta_x);
I = zeros(n*m,1);
%delta_x = 100;
%delta_y = 100;
%R = 10*10^6;
%H = 10*10^6;
%index_ij = 0;
%for k=1:40
%CC(k,:)=C((k-1)*40+1:(k-1)*40+40,1);
%end
for j = 1 : 1 :n
for i = 1: 1: m
index_ij = (j-1)*n + i;
index_i = ((i-n/2)-0.5)*delta_x;
index_j = ((j-m/2)-0.5)*delta_y;
I(index_ij,1) = H - (sqrt((R^2-index_i^2-index_j^2)));
%C(index_ij,1) = sqrt((R^2-index_i^2-index_j^2));
end
end
%O = C;
%function [A] = finalA(Y_s, sigma_s, delta_x, delta_y, d, s, b)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Determining the row index matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Inputs :
%b = beam width diameter (nm)
%s = lenght of cube in x direction (micro m)
%d = length in y direction (micro m)
% Y_s = the erosion rate (micro m/sec)
% sigma = standard deviation
% xx = co ordiantes of th point being machined
% yy = the co ordinates of the point where the effects of machining are
% observed due to actual process going on at point x_ij
% delta x = delta y = pixel size (nm)
%Outputs :
% a N x 1 matrix comprising of the constant terms. (row matrix)
% a 25 x n matrix comprising of the constant terms. (column index matrix)
% a 5 x 5 matrix comprising of the concerned vlaues which are within the
% radius of effect of point of application. (25 values)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Model Parameters :
%n = floor((d*10^3)/b);
%m = floor((s*10^3)/b);
A = [1:m*n];
B = repmat(A,(o+o+1)^2,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Determining the column index matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C = zeros(m,n);
i = 0;
for index_i = 1:1:m
for index_j = 1:1:n
C(index_i,index_j) = (i*m) + index_j;
end
i = i+1;
end
C = reshape(1:m*n,m,n);
%K = R;
D = padarray(C,[o o], m*n+1);
%K = E;
E = im2col(D,[o+o+1 o+o+1],'sliding');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Determining the Value of the 5 x 5 (concerned values) matrix by
%the optimal dwell time approach.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%n = floor((d*10^3)/b);
F = zeros(o+o+1,o+o+1);
index_ij = 0; % initilising the value of variable index_ij as zero
for i = -2:1:2
for j = -2:1:2
index_ij = index_ij+1;
F(index_ij) = Y_s/(2*pi)*exp(-((i*delta_x)^2+(j*delta_y)^2)/(2*sigma_s^2));
%F(index_ij) = Y_s/(2*pi)*exp(-(((i-1)+.5)*delta_x)^2+((j-1)+.5)*delta_y)^2)/(2*sigma_s^2));
% value of the concerned terms within the radius of effect
end
end
G = F(:);
H = repmat(G,1,m*n);
%L =P;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sparse Matrix %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = sparse(B(:),E(:),H(:),m*n,m*n+1);
A = A(:,1:m*n);
%O = A;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P = transpose(A)*A;
Q = -transpose(I)*A;
v = ones(m*n,1);
v1 = inf(m*n,1);
sum = (v1-v);
tol = 0.000001;
while sum>tol
for k = 1 : 200
v1 = (abs(transpose(Q))./(P*v)).*v;
sum = abs(v1-v);
end
v = v1;
end
O = v1;
0 Comments
Answers (1)
Walter Roberson
on 1 Sep 2011
The exact amounts of memory available depend upon the release of MATLAB, and upon the operating system being used. To achieve your goal, you would have to research the worst-case scenario, and would probably have to obtain another computer, and the corresponding operating system, and another version of MATLAB, so that you could test what you need to do to make it work on "any desktop with ram at least 3gb".
It is difficult to see how porting your code to the worst-case situation could be considered to be "urgent". Is a hydroelectric dam going to fail within the next 4 hours in Rhwanda if they cannot calculate the exact size to machine a screw with your program?
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!