Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
What is ceil doing here and how do I vectorize this?

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 22 Feb, 2012 21:43:20

Message: 1 of 13

Hello,
can someone explain to me what exactly the function ceil does to Matrix A in this code:

A = [2 6; 8 4];
B = A( ceil( 0.5:0.5:end ), ceil( 0.5:0.5:end )

And this code:

a = 1:3;
N = 3
b = a(ceil((1:N*numel(a))/N))

And please could someone suggest how to vectorize this code below. I have in mind to use remap and that funny "ceil" method, but I'd like some suggestion first (you are welcomed to assign any vector to "t" and "eigen":

tic
returnorthocheck = zeros(length(t),1);
returnchecko = zeros(length(t),length(t));
for nn = 1:(length(t))
    for nnn = nn+1:length(t)
        kvecc = (1:6)';
        eigfuntocheck = @(kkk)quadgk(@(x)conj(eigen((nn),kkk).*exp(1i.*t(nn).*x)+eigen((nn),kkk+6).*exp(-1i.*t(nn).*(x))).*(eigen(nnn,kkk).*exp(1i.*t(nnn).*x)+eigen(nnn,kkk+6).*exp(-1i.*t(nnn).*(x))),0,bbonds(kkk));
        orthochec1 = arrayfun(eigfuntocheck,kvecc);
        returnorthocheck(nnn-1) = sum(orthochec1);
    end
    returnchecko(:,nn) = returnorthocheck;
end
toc

AND FINALLY, I am trying to compute this determinant below for a 78*78 matrix, but maltab fails to do so, and stalls (maybe after a looong time it will compute), but who knows. Obviously, the matrix has symbolic entries, and some...ok lots of exponential entries, but should that really affect things that badly? I mean I am only asking for Matlab to return a symbolic expression (a long one albeit)...

det_of_t = sqrt(conj(det(QG.T)));
            iden_mat = eye(QG.numB);
            secfun = @(k) real(det_of_t*exp(-1i/2*k*L)...
                * det(iden_mat-diag(exp(1i*k*QG.Ls))*QG.T));

T is a 78*78 matrix with real entries (nothing symbolic there). In fact, k is the only symbolic entry above. Any suggestions on how to speed things up in both issues highlighted above guys?

Subject: What is ceil doing here and how do I vectorize this?

From: dpb

Date: 22 Feb, 2012 22:17:42

Message: 2 of 13

On 2/22/2012 3:43 PM, Leo Kay wrote:
> Hello, can someone explain to me what exactly the function ceil does to
> Matrix A in this code:
>
> A = [2 6; 8 4];
> B = A( ceil( 0.5:0.5:end ), ceil( 0.5:0.5:end )

Try this...(first, what is the value of end for A?)

ceil(0.5:0.5:2)

doc ceil

I'll admit it's a construct I've not seen before... :) Hadn't realized
END would work nested in a call like that; would've never thought to try it.

--

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 22 Feb, 2012 23:08:13

Message: 3 of 13

dpb <none@non.net> wrote in message <ji3pi4$m8s$1@speranza.aioe.org>...
> On 2/22/2012 3:43 PM, Leo Kay wrote:
> > Hello, can someone explain to me what exactly the function ceil does to
> > Matrix A in this code:
> >
> > A = [2 6; 8 4];
> > B = A( ceil( 0.5:0.5:end ), ceil( 0.5:0.5:end )
>
> Try this...(first, what is the value of end for A?)
>
> ceil(0.5:0.5:2)
>
> doc ceil
>
> I'll admit it's a construct I've not seen before... :) Hadn't realized
> END would work nested in a call like that; would've never thought to try it.
>
> --

Well dpb your guess for "end" is as good as mine (I know what celil does, that is rounding up, but it doesnt explain how it works to index the matrix and EXPAND IT that is very puzzling to me lol). In fact, I am even amazed that the code runs at all LOL. "end" is NOT specified, yet it seems to infer something from the matrix. I admit I AM PUZZLED. Maybe Steven, or Richard understand what's going on lol... I am loving that "ceil" method, but yea, I dont get it either lol.

Subject: What is ceil doing here and how do I vectorize this?

From: dpb

Date: 22 Feb, 2012 23:19:08

Message: 4 of 13

On 2/22/2012 5:08 PM, Leo Kay wrote:
...

> Well dpb your guess for "end" is as good as mine (I know what celil
> does, that is rounding up, but it doesnt explain how it works to index
> the matrix and EXPAND IT that is very puzzling to me lol). In fact, I am
> even amazed that the code runs at all LOL. "end" is NOT specified, yet
> it seems to infer something from the matrix. I admit I AM PUZZLED. Maybe
> Steven, or Richard understand what's going on lol... I am loving that
> "ceil" method, but yea, I dont get it either lol.

I "get" it fully; I only commented that I didn't realize the reference
to END would be resolved inside a function call in the indexing expression.

doc end

for the explanation. Second definition.

Try

A(end,end)
A(1:end,1)

etc., at command line.

Note again the example I suggested you try and how it relates to the
result you get from the actual code.

--

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 22 Feb, 2012 23:56:13

Message: 5 of 13

dpb <none@non.net> wrote in message <ji3t5e$vb9$1@speranza.aioe.org>...
> On 2/22/2012 5:08 PM, Leo Kay wrote:
> ...
>
> > Well dpb your guess for "end" is as good as mine (I know what celil
> > does, that is rounding up, but it doesnt explain how it works to index
> > the matrix and EXPAND IT that is very puzzling to me lol). In fact, I am
> > even amazed that the code runs at all LOL. "end" is NOT specified, yet
> > it seems to infer something from the matrix. I admit I AM PUZZLED. Maybe
> > Steven, or Richard understand what's going on lol... I am loving that
> > "ceil" method, but yea, I dont get it either lol.
>
> I "get" it fully; I only commented that I didn't realize the reference
> to END would be resolved inside a function call in the indexing expression.
>
> doc end
>
> for the explanation. Second definition.
>
> Try
>
> A(end,end)
> A(1:end,1)
>
> etc., at command line.
>
> Note again the example I suggested you try and how it relates to the
> result you get from the actual code.
>
> --
>
>
>

Alright yea, funnily enough I was using that sort of logical indexing prior without realizing the relation... Thanks for pointing it out.

Any suggestion for my other problems, the more prominent one being the determinant issue, it's bugging me because I want to move onto higher dimension matrices, a bit hopeless for now.

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 23 Feb, 2012 17:27:21

Message: 6 of 13

Any other suggestion concerning working out symbolic determinants of large non-sparse matrices?

Subject: What is ceil doing here and how do I vectorize this?

From: Steven_Lord

Date: 23 Feb, 2012 18:19:26

Message: 7 of 13



"Leo Kay" <anousleshommes@hotmail.com> wrote in message
news:ji5stp$fvj$1@newscl01ah.mathworks.com...
> Any other suggestion concerning working out symbolic determinants of large
> non-sparse matrices?

Yes: don't.

What problem are you trying to use the determinant computation to solve?
There may be an alternate approach that doesn't require computing the
determinant of a large matrix.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 23 Feb, 2012 19:42:18

Message: 8 of 13

"Steven_Lord" <slord@mathworks.com> wrote in message <ji5vvd$pss$1@newscl01ah.mathworks.com>...
>
>
> "Leo Kay" <anousleshommes@hotmail.com> wrote in message
> news:ji5stp$fvj$1@newscl01ah.mathworks.com...
> > Any other suggestion concerning working out symbolic determinants of large
> > non-sparse matrices?
>
> Yes: don't.
>
> What problem are you trying to use the determinant computation to solve?
> There may be an alternate approach that doesn't require computing the
> determinant of a large matrix.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


Well, the problem is to with quantum transport... So Matlab is not suited for such endeavours? Is there any platform (say c++) that could handle such symbolic computations for very large matrices?

Subject: What is ceil doing here and how do I vectorize this?

From: Bruno Luong

Date: 23 Feb, 2012 20:02:12

Message: 9 of 13

"Leo Kay" <anousleshommes@hotmail.com> wrote in message <ji64qq$dlf$1@newscl01ah.mathworks.com>...

>
> Well, the problem is to with quantum transport... So Matlab is not suited for such endeavours?

The symbolic determinant requires summing 78! (factorial) products of the matrix elements, which is

>> factorial(78)

ans =

  1.1324e+115

number of products. If your computer can compute 1000 products by seconds, it takes

factorial(78) / (3600*1000*24*356) = 3.6817e+104 years to compute.

Currently the universe age is about 1.4e10 years. you can wait it for loooong time.

Bruno

Subject: What is ceil doing here and how do I vectorize this?

From: Steven_Lord

Date: 23 Feb, 2012 21:59:19

Message: 10 of 13



"Leo Kay" <anousleshommes@hotmail.com> wrote in message
news:ji64qq$dlf$1@newscl01ah.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <ji5vvd$pss$1@newscl01ah.mathworks.com>...
>>
>>
>> "Leo Kay" <anousleshommes@hotmail.com> wrote in message
>> news:ji5stp$fvj$1@newscl01ah.mathworks.com...
>> > Any other suggestion concerning working out symbolic determinants of
>> > large non-sparse matrices?
>>
>> Yes: don't.
>>
>> What problem are you trying to use the determinant computation to solve?
>> There may be an alternate approach that doesn't require computing the
>> determinant of a large matrix.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> To contact Technical Support use the Contact Us link on
>> http://www.mathworks.com
>
>
> Well, the problem is to with quantum transport...

More details, please.

> So Matlab is not suited for such endeavours? Is there any platform (say
> c++) that could handle such symbolic computations for very large matrices?

That's not what I'm saying. Suppose you were trying to use the determinant
to determine if the matrix is singular. Easy, right?

The identity matrix is nonsingular, agreed?

E = eye(500);
det(E) % 1

Multiplying a matrix by a _nonzero_ constant does not change whether or not
it's singular, agreed?

E2 = E*0.1;
det(E2) % 0??? Underflow!

Now yes, I know you're performing symbolic calculations not numeric
calculations but the symbolic determinant wouldn't be much better; it would
tell you that the determinant is 10^(-500).

There are better tools to use to determine if a matrix is singular; if
that's the problem you're trying to solve then we can discuss some of those
tools and techniques.

If the _specific_ problem you're trying to solve is different, tell the
group what you're trying to do and perhaps there's a better way in MATLAB to
solve that problem than det(sym(...)).

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 24 Feb, 2012 05:19:37

Message: 11 of 13

> > Well, the problem is to with quantum transport...
>
> More details, please.
>
> > So Matlab is not suited for such endeavours? Is there any platform (say
> > c++) that could handle such symbolic computations for very large matrices?
>
> That's not what I'm saying. Suppose you were trying to use the determinant
> to determine if the matrix is singular. Easy, right?
>
> The identity matrix is nonsingular, agreed?
>
> E = eye(500);
> det(E) % 1
>
> Multiplying a matrix by a _nonzero_ constant does not change whether or not
> it's singular, agreed?
>
> E2 = E*0.1;
> det(E2) % 0??? Underflow!
>
> Now yes, I know you're performing symbolic calculations not numeric
> calculations but the symbolic determinant wouldn't be much better; it would
> tell you that the determinant is 10^(-500).
>
> There are better tools to use to determine if a matrix is singular; if
> that's the problem you're trying to solve then we can discuss some of those
> tools and techniques.
>
> If the _specific_ problem you're trying to solve is different, tell the
> group what you're trying to do and perhaps there's a better way in MATLAB to
> solve that problem than det(sym(...)).
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


Hey Steve. As ever, right on cue. Well I am interested in making the matrix singular, but there is an infinity of possible (discrete) values on the real line that would satisfy once the determinant equation is solved. And those specific values are what I look for. Then I replace those values in the symbolic entries of my matrix and look for eigenvalues and eigenvectors of the matrix for which I have substitute the ymbolic entry with the value for which the matrix is singular. I dont know if htere is any other way to perform such operation to be honest but I await your answer.
Best.

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 24 Feb, 2012 05:25:17

Message: 12 of 13

> > Well, the problem is to with quantum transport...
>
> More details, please.
>
> > So Matlab is not suited for such endeavours? Is there any platform (say
> > c++) that could handle such symbolic computations for very large matrices?
>
> That's not what I'm saying. Suppose you were trying to use the determinant
> to determine if the matrix is singular. Easy, right?
>
> The identity matrix is nonsingular, agreed?
>
> E = eye(500);
> det(E) % 1
>
> Multiplying a matrix by a _nonzero_ constant does not change whether or not
> it's singular, agreed?
>
> E2 = E*0.1;
> det(E2) % 0??? Underflow!
>
> Now yes, I know you're performing symbolic calculations not numeric
> calculations but the symbolic determinant wouldn't be much better; it would
> tell you that the determinant is 10^(-500).
>
> There are better tools to use to determine if a matrix is singular; if
> that's the problem you're trying to solve then we can discuss some of those
> tools and techniques.
>
> If the _specific_ problem you're trying to solve is different, tell the
> group what you're trying to do and perhaps there's a better way in MATLAB to
> solve that problem than det(sym(...)).
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


The other thing to note is that this is like finding the eigenvector corresponding to the 0 eigenvalue (once I substitute in the value that makes the matrix singluar I look for the eigenvector with minimal absolute eigenvalue). But I cant start looking for eigenvectors/values of symbolic matrices.

Subject: What is ceil doing here and how do I vectorize this?

From: Leo Kay

Date: 26 Feb, 2012 08:45:31

Message: 13 of 13

"Steven_Lord" <slord@mathworks.com> wrote in message <ji6crn$au8$1@newscl01ah.mathworks.com>...
>
>
> "Leo Kay" <anousleshommes@hotmail.com> wrote in message
> news:ji64qq$dlf$1@newscl01ah.mathworks.com...
> > "Steven_Lord" <slord@mathworks.com> wrote in message
> > <ji5vvd$pss$1@newscl01ah.mathworks.com>...
> >>
> >>
> >> "Leo Kay" <anousleshommes@hotmail.com> wrote in message
> >> news:ji5stp$fvj$1@newscl01ah.mathworks.com...
> >> > Any other suggestion concerning working out symbolic determinants of
> >> > large non-sparse matrices?
> >>
> >> Yes: don't.
> >>
> >> What problem are you trying to use the determinant computation to solve?
> >> There may be an alternate approach that doesn't require computing the
> >> determinant of a large matrix.
> >>
> >> --
> >> Steve Lord
> >> slord@mathworks.com
> >> To contact Technical Support use the Contact Us link on
> >> http://www.mathworks.com
> >
> >
> > Well, the problem is to with quantum transport...
>
> More details, please.
>
> > So Matlab is not suited for such endeavours? Is there any platform (say
> > c++) that could handle such symbolic computations for very large matrices?
>
> That's not what I'm saying. Suppose you were trying to use the determinant
> to determine if the matrix is singular. Easy, right?
>
> The identity matrix is nonsingular, agreed?
>
> E = eye(500);
> det(E) % 1
>
> Multiplying a matrix by a _nonzero_ constant does not change whether or not
> it's singular, agreed?
>
> E2 = E*0.1;
> det(E2) % 0??? Underflow!
>
> Now yes, I know you're performing symbolic calculations not numeric
> calculations but the symbolic determinant wouldn't be much better; it would
> tell you that the determinant is 10^(-500).
>
> There are better tools to use to determine if a matrix is singular; if
> that's the problem you're trying to solve then we can discuss some of those
> tools and techniques.
>
> If the _specific_ problem you're trying to solve is different, tell the
> group what you're trying to do and perhaps there's a better way in MATLAB to
> solve that problem than det(sym(...)).
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


What I am now exploring is discretising the real, create a for-loop that will go through that interval and check if there are values that satisfy symbolic determinant of the matrix = 0. But this would a very expensive to do time-wise since I'd need to discretise my interval very finely, so Im not keen on trying that. Any other suggestion appreciated.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us