Bluebit Software
Bluebit Software Support Forum
 Home          Members     Calendar     Who's On

Welcome Guest ( Login | Register )
        



Translating MatLab code Expand / Collapse
Message
Posted Wednesday, March 09, 2005 9:12 AM Post #51
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
Hi,
I am in the process of attempting to convert a number of old MatLab routines to utilize the .NET Matrix Library. I've run into two issues which seem to be more painful than they should be:

1) The MatLab '/' operator [matrix division]. I am able to [I believe] properly simulate the following matlab statement:

x = A/B

In VB.NET:

x = B.Transpose().Solve(A.Transpose()).Transpose()

Is there an easier way to perform this function? I arrived at this solution by performing the translation as described in the MatLab docs:

A / B = (B' \ A' )'

According to the MatLab docs, A\B == the solution to Ax = B for x, so I assumed that the .Solve() method of the matrix class would provide me similar behavior. Does this seem reasonable?

2) Assigning entire rows/columns of data. It would be really handy to be able to set an entire row/column of data similar to what can be done in MatLab, e.g.:

x(:,1) = y [where len(y) = rank(x)]

Right now, I just have a simple method that accepts a column/row and a vector to insert and iterates over the array inserting the appropriate rows. In the end, it may just be syntactic sugar to support such a method, but it would make things a little easier to deal with.

Thanks!
Ben
Posted Wednesday, March 09, 2005 10:34 AM Post #202
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support
Hi

Regarding (1):
==============
If matrix A is invertible you can substitute
x = B.Transpose().Solve(A.Transpose()).Transpose()
by
x = A.Times(B.Inverse())
Please try the following and compare the results with those found in this page : http://www.egr.up.edu/contrib/nguyentom/Matlab/

Sub Main()
Dim A As New Matrix(New Double(,) {{1, 2, 3}, {4, 5, 6}, {7, 8, 0}})
Dim B As New Matrix(New Double(,) {{2, 4, 6}, {0, 3, 7}, {9, 8, 1}})
Dim C As Matrix
C = A.Times(B.Inverse)
Console.WriteLine(C)
Console.Read()
End Sub

Regarding (2)
=============
You are absolutely right. In the next version (2.2) we' ve planned to incude two new methods, FillRow and FillColumn having various overloads taking values from vectors, arrays, constants, that will do the function you are describing.

Thank you for trying .NET Matrix Library and your suggestions,




Trifon Triantafillidis

Lead Developer

Bluebit Software

Posted Wednesday, March 09, 2005 10:49 AM Post #203
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support

I forgot to mention above that Transpose is not an expensive operation and "x = B.Transpose().Solve(A.Transpose()).Transpose()" may look a bit lengthy but is not that bad.



Trifon Triantafillidis

Lead Developer

Bluebit Software

Posted Wednesday, March 09, 2005 2:53 PM Post #204
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
Thanks for the reply. I had thought about using the A * inv(B) shortcut, but the MatLab docs state that they aren't strictly equivalent:

quote:

Slash or matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A = (A'\B')'



I guess my question then becomes "how close is 'roughly'" I'll have to test both methods and see what the results look like.

Thanks!
Ben
Posted Wednesday, March 09, 2005 3:16 PM Post #205
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support
When B is not square or is singular then you cannot use x = A.Times(B.Inverse).

x = B.Transpose().Solve(A.Transpose()).Transpose() will always return a result provided matrix B has the same number of columns as A.

More about the Solve method: http://www.bluebit.gr/NET/Library/Matrix-Solve.html




Trifon Triantafillidis

Lead Developer

Bluebit Software

« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trifon

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 6:51am

Powered by InstantForum.NET v4.1.4 © 2012
Execution: 0.266. 9 queries. Compression Disabled.
.NET Matrix Library