Skip to main content
13-Aquamarine
March 8, 2011
Question

MATHCAD API: Limit on size of matrix when assigning values

  • March 8, 2011
  • 18 replies
  • 13525 views

Hello there.

I am currnelty explorign the use of the mathcad API for generating a matrix of data from another application.

I am using VS2010 Professional and VB.NET. I am using the mathCAD API for doing this. I am using MathCAD V14.0.2.5

It appears that there is a limit on the size of the matrix one can create through using the setelement mehtod of the MatrixValue class.

My original matrix was of size 6800 rows x 21 cols. When i try and view this matrix or assign this matrix to a new variable MathCAD shows no vlaue for this matrix. Teh matrix is composed of strings - i ahve to use strings as the data is of a variant/object type i.e. strings/doubles/integers. It seemed to crash when I got ro row 480. For rows less than this i was able to view the matrix in mathcad and assign the matrix to a another user defined valriable as well as extract elements for given indices.

As a test I simply ran a loop for a matrix of 480 rows x 18 columns and assigned an integer value of 1 for every elment. In this instance I was able to get mathcad to read the matrix; hwn trying to display it gave the following:

POINTSMatrix:=BigMatrix{480x19}

If I increase the range to 800x19 I cannot get any value for the matrix. If I use 600x19 it still works

Is there a limit on teh maximum size of a matrix that can be assigned using the SetElement method? IS there a better more efficient way fo assigning data to a very large matrix in mathcad using its API? I want to use the Automation API and not manually do this using table.s

My code for this is given below, I am using ealry bound code, hence Option Explicit = true, and using Ctype statements:

Dim mcdObject As New Object

Dim mcdPointsMatrix As Mathcad.MatrixValue

Dim mcdMatrixNew As Mathcad.MatrixValue

mcdMatrixNew = CType(Interaction.CreateObject("Mathcad.MatrixValue"), Mathcad.MatrixValue)

Try
mcdPointsMatrix = CType(mcdWorkSheet.GetValue("Points"), Mathcad.MatrixValue)
bMatrixExists = True
Catch ex As Exception

bMatrixExists = False

end Try

For i As Integer = 600 - 1 To 0 Step -1
For j As Integer = 18 To 0 Step -1
If bMatrixExists = False Then
mcdMatrixNew.SetElement(i, j, 1)
Else
mcdPointsMatrix.SetElement(i, j, 1)
End If
Next
Next

If bMatrixExists = False Then
mcdWorkSheet.SetValue("Points", mcdMatrixNew)
Else
mcdWorkSheet.SetValue("Points", mcdPointsMatrix)
End If

18 replies

1-Visitor
March 8, 2011

Make sure you create the last element first. Otherwise Mathcad keeps duplicating the old matrix as it adds the extra row/column when the next index is used.

I vaguely remember an absolute maximum number of elements that is related to your available contiguous memory size which may be an issue. Not sure if it still stands.

Most of my work has been simple API stuff from VBscript or Matlab.

Philip

tslewis13-AquamarineAuthor
13-Aquamarine
March 8, 2011

Hi Phillip

thanks for the repsonse.

yes, good point but in the code above, i did initialize the array by first starting with the highest element and workign backwards.

What is the largest matrix you have created using the MathCAD API with VBScript/Matlab? could you share some code? Im testing my matrix and MathCAD keeps hanging unle sthe arrya is small. I tried an 8000x30 matrix called TEST which to me is small by mathcad stabards. The sheet keeps hanging when I assign X:=TEST.

If i explcitely define the same array in the MathCAD sheet using range assignments i.e

i:= 0..8000

j:=0..30

TESTi,j:="hdhskjhadskjhsakjhsa"

The matriux is cimputed super quick in time in the mathCAD sheet.

It seems that the API is not working properly.

Im using .NET, VS2010 and Win 7 x64

Thanks Steve

19-Tanzanite
March 8, 2011

SetValue can create the matrix of strings in one operation. So create the matrix in VB, for example VBMatrix, and then call SetValue, for example

SetValue "MathcadMatrix", VBMatrix

will create MathcadMatrix as the variable

tslewis13-AquamarineAuthor
13-Aquamarine
March 8, 2011

Hi Richard,

thanks for response. I tried your suggesiton but as expected, it made no difference.

Dim strTest(8000, 30) As String

For i As Integer = 8000 To 0 Step -1

For j As Integer = 30 To 0 Step -1

strTest(i, j) =

"hadkjhsadkhsakjhdkjsahdkjahdkjahskkdhakhskdkhakdksahk"

Next

Next

If bMatrixExists = False Then

Try

mcdWorkSheet.SetValue(

"TEST", strTest)

Catch ex As Exception

Dim btets As Boolean = False

End Try

Else

Try

mcdWorkSheet.SetValue(

"TEST", strTest)

Catch ex As Exception

Dim btets As Boolean = False

End Try

End If

What is the maximum matrix you have assigned using the MathCAD API and .NET?

thanks

Steve

tslewis13-AquamarineAuthor
13-Aquamarine
February 13, 2014

three years later, I still have the same issue, pathetic

19-Tanzanite
February 13, 2014

I would be amazed if they had fixed this. They are putting minimal effort into Mathcad 15 now, and a bug that affects so few people will never make iti high enough up the list. All their effort is going into Prime. At the current rate of progress maybe in another three years you will be able to do what you want in Prime. I wouldn't bet any money on that though

1-Visitor
July 16, 2014