cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

MATHCAD API: Limit on size of matrix when assigning values

Marble

MATHCAD API: Limit on size of matrix when assigning values

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 18

Re: MATHCAD API: Limit on size of matrix when assigning values

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

Re: MATHCAD API: Limit on size of matrix when assigning values

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

Re: MATHCAD API: Limit on size of matrix when assigning values

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

Re: MATHCAD API: Limit on size of matrix when assigning values

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

Re: MATHCAD API: Limit on size of matrix when assigning values

I have no idea what you mean by contagious smemory, but I supect what I want to do using the API is affected by this and it is currently impossible to do.

The documentaiton on the API is very poor compared to others like CATIA/Excel etc.

It seems crazy, but I cannot assign a matrix larger than 400x30 with a string value of "TEST" assigned ot each element. This is crazy. It is easliy possible to assign arrays far larger than this within the mathcad environment (in process) using explict range assignments on the sheet. Ridiculous. What use is the API if you can only work with such tiny matrices?

i.e. i:=0..400 j:=0..30 TESTi,j:="TEST"

Can anyone confirm what the maxium array size they were able to create within mathCAD using the API?

Is this poor performance due to incompatibilty of the Mathcad COM model with .NET when running out of process? I understand that CATIA has similar issues in that running out of process on a 64 bit OS is actually slower than runing in process using VBA scripts.

Currently, I simply cannot use MathCAD for out of process .NET situations and will have to consider another option such as Matlab/Mathematica/Maple

Id be interested if someone else could test the above. Its quite possible Im doing something really silly!!!!!

thanks

Re: MATHCAD API: Limit on size of matrix when assigning values

It appears to be a bug. A long standing one too. And it has nothing to do with dotnet.

The attached worksheet has a scripted component in to that can be use to create a matrix via the API. Attempts to create a large matrix fail in versions 11, 13 and 15. The fact that it fails in version 11 is significant, because they rewrote a large chunk of the compute engine for version 12. In version 11 the largest matrix seems to be larger, but not much, and when it does create it it is MUCH faster. Above a certain size though (not very big - 1000x30 will fail) version 11 simply exits with no messages and no warning! The behavior in versions 13 and 15 is similar. If you try to create a matrix that is too large Mathcad will either hang or crash.

The reason I say it's a bug, rather than an intentional limitation, is both because there is no reason why such a limitation should have been imposed, and because of the completely ungraceful way Mathcad handles it. If it were intentional then I would expect an error message, or, worst case, that it would simply do nothing. Not that Mathcad would crash!

Re: MATHCAD API: Limit on size of matrix when assigning values

Hi Richard.

Thank yo for looking at this and confirming it is abug with MathCAD.

This is very annoying and has thrown a spanner in the works.

Do you think it possibel for PTC to correct this and release and amended MathCAD API to address this severe limitation? Do you know who to contact? Is MathCAD prime also limited by this or is a new API used?

Thanks

Steve

Re: MATHCAD API: Limit on size of matrix when assigning values

Do you think it possibel for PTC to correct this and release and amended MathCAD API to address this severe limitation?

Maybe. It's evidently been there for a long time. I don't know if that means it's very difficult to fix, or they just didn't know about it or it was too low priority to get fixed.

Do you know who to contact?

If you have current maintenance you can log a formal report via the PTC website. If you are a single user you have no contact channel.

Is MathCAD prime also limited by this or is a new API used?

Prime has a new API, but it has not been released to the public for version 1.0 so that will not do you any good.

Re: MATHCAD API: Limit on size of matrix when assigning values

Man, this is a real pain.

The best solution I have is to stream the contents of the matrix values I want to create to an intermediate text comma delimted file. I will then call the file "Variable_file.txt" and then reassign this string as a variable to the WRITEFILE method. Problem with this is that it requires the user to set up the WRITEFILE construct beforehand so it is not a fully live and dynmaic solution which is the reason why I wanted to use the API in the first place!!!

Example:

'create txt file dynamically from data from external application, and pass name of inetrmediate text file to M_filename as string value using MathCAD API

Mfilename:="M_file,txt"

M:= READFILE(Mfilename,"delimited)

I tested this on a matrix of 6000x30 strings and it worked in less than 10seconds.

Is there any way I can dynamically create the READFILE(Mfilename,"delimited) construct and assing it to a variable?

Thank you so much for looking in to my problem and confirming what I suspected,

cheers

Announcements