turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-01-2014 10:21 PM

How would I write a function module that will input 3 identical sized matrices (not knowing the size) and retunr the one that has the largest determinant. The function should check that the matrices are square and all the same size.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to arbongard

05-02-2014 05:51 AM

How about the following?

.

start maxdet(a, b, c);

nr = nrow(a) || nrow(b) || nrow(c);

nc = ncol(a) || ncol(b) || ncol(c);

if all(nr=nc) & max(nr)=min(nr) then do;

i = ( det(a) || det(b) || det(c) )[<];

if i = 1 then return(a);

else if i = 2 then return(b);

else if i = 3 then return(c);

end; else return(.);

finish;

.

Not sure why you want to do this. What if two matrices are tied for the largest determinant?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to IanWakeling

05-02-2014 10:10 AM

I am trying to figure that out.

I think I would want to print both of them if they were tied to show that they had a tie. how would I do that?

also how would I make the matrix or matrices show up in the output log.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to arbongard

05-02-2014 10:32 AM

If you get the three determinants into a vector called d, then you could use syntax like i = loc(d=max(d)) to get the index numbers of all determinants equal to the max. You could then adapt the if statements at the end along the lines of if any( i =1) then print a; etc...

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to IanWakeling

05-02-2014 02:05 PM

so instead of:

i = ( det(a) || det(b) || det(c) )[<];

I should use:

i = loc(d=max(d)); This would give me the max det value or would this give me the matrix with max determinate?

I want the print out the **matrix (just the matrix)** with the max determinate.

Every thing is fine after the **then do **statement.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to arbongard

05-03-2014 04:17 AM

It will give you the index number of the matrix with the max determinant. I suggest you look into the LOC() function as it has many uses. Either look in the documentation or read Rick's excellent blog, he has written about LOC several times:

Beware the naked LOC - The DO Loop

LOC: The most useful function you’ve never heard of - The DO Loop

I suggest you replace the old definition of i, with:

d = det(a) || det(b) || det(c);

i = loc( d = max(d));

Note there is no nakedness here as the vector of three determinants (d) must have at least one element equal to the maximum. You now need to think about handling ties. Most of the time 'i' will be a 1x1 matrix containing the number 1,2 or 3 of the matrix a,b or c with the max determinant. But it might be a 1x2 or a 1x3 matrix of index numbers if there are ties. You need to add code to handle these different conditions, perhaps print a warning message about the number of ties.