problem in initializing sparse matrix

조회 수: 5 (최근 30일)
vijay
vijay 2013년 5월 8일
I encountered this strange counter intuitive thing, a = 150e-6; b = 1e3; c = 1e4;
d = a*b*c; % now d = 1500 is definitely an integer mathematically but A = sparse(2*d,2*d) says "Error using ==> sparse Sparse matrix sizes must be non-negative integers less than MAXSIZE as defined by COMPUTER. Use HELP COMPUTER for more details."
d is displayed as 1.500000(couple of more zeors)e+003. it is equal to 1500. i tried forcing by int32(); then another error comes. but initializing A = sparse(2*1.5e3,2*1.5e3) does fine. any clue what i'm missing. many thanks for the help on this strange issue. I guess i'm missing some thing obvious but can't catch it.

채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 5월 8일
hi,
it worked well, no problem and d=1500, try to use of these functions :
d=floor(d);
d=ceil(d);
d=round(d);
  댓글 수: 2
vijay
vijay 2013년 5월 8일
thanks a lot youssef,
It works with suggested functions. i include a more working error for future,
%%
density = 150e-6;
width = 10000;
length =1000;
temp_number= (density*width*length);
global_number= (temp_number)
A2 = sparse(2*global_number, 2*global_number);
%A3 = sparse(2*1.5000e+3,2*1.5000e+3); % this was fine
%%
A2 gives error, fixing to floor(A2) does fixes it. but still i'm not clear if this is bug of having different interpretation of integers. could you please say on what may be the reason for it. and why int32() was failing
Youssef  Khmou
Youssef Khmou 2013년 5월 8일
maybe the reason is : it is written in the documentation of 'int32()' that If the stored integer word length is too big for an int32 the returned value saturates to an int32, "saturates", but not rounded .

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by