turn on suggestions

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

Showing results for

- Discussion Forums
- :
- Additional NI Product Boards
- :
- MATRIXx
- :
- Re: Matrix operations in SystemBuild

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report to a Moderator

10-05-2009 07:03 AM

Hi,

I'm a beginner trying to implement a Model Predictive Controller (MPC) controller in SystemBuild for my final thesis project. This involves a bunch of matrix operations being performed and some resulting matrices being sent to a UserCode Fortran script, solving a Quadratic Programming problem. At the moment I have two specific, and I hope quite simple, questions:

- How do I sum two matrices together? There appears to be no block for this and I only get the 'Summer Block' to sum together scalars.
- Is there an efficient way to import matrix data from a Matlab environment? At present I have defined constant blocks representing matrices but since UNIX doesn't allow copy-paste of parameter values directly into the parameter setting box I would have to manually type in huge amounts of data, can I get around this?

It should be noted that the solutions must work with the AutoCode feature.

Any advice or source of information is appreciated, I find the SystemBuild User Guide a bit thin.

Best regards,

Alex

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report to a Moderator

10-06-2009 06:53 PM

The SystemBuild summer block is an element-by-element summer.

To add two matricies, set the number of branches to 2 (the default) and set the number of outputs to match the number of matrix elements.

To make it easier to connect matricies between SystemBuild blocks, You should set the block InputPins and OutputPins modes to vector and set inputnames and outputlabels as vectors labels.

Here is an SBA script example you can cut and paste into the Xmath command line which adds two constant blocks (matrix) using a summer.

build

createsuperblock "matrixsum",{outputs=12}

createblock "constant",{constantvalue=3*ones(3,4),constantname

createblock "constant",{constantvalue=4*ones(3,4),constantname

createblock "summer",{signs=[1,1],outputs=12,id=3,outputlabel=

modifyblock 3,{icontype="Alternate",color=1,showoutputlabels="

createconnection 1,3

createconnection 2,3

createconnection 3,0

t=[0,1]';

[,y] = sim("matrixsum",t)

Reading Matlab data into Xmath is tricky because the Matlab save format is closed and changing.

If you can write out you Matlab data in ASCII format and remove and headers or labels and are

just left with just numbers seperated by spaces. You could use the Xmath read command

to load it into Xmath as a matrix.

**A = read("$XMATH/demos/read_ex.ascii",10,10,"ascii")? **

Check out Xmath Math User Guide page C-16 Loading In External Data (read)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report to a Moderator

10-08-2009 08:43 AM

Thanks a lot! That solved my problems for the time being