Skip to main content
12-Amethyst
July 13, 2024
Solved

custom function fc

  • July 13, 2024
  • 2 replies
  • 2299 views

333111111

 

222

 

Greetings, I tried to create custom functions in mathcad and it asks to do so, however when I tried to create the function fc and fc1 I found an error message

----------------------------------------------

Translated the text from Spanish to English using google translate

Body - Saludos intente crar funciones personalizadas en mathcad y pude hacerlo, sin embargo cuando intente crear la funcion fc y fc1 encontre un mensaje de error

--By Community Moderation Team

----------------------------------------------

Best answer by JeffH1

There's just one problem here, the indices on the return vector/matrix are switched.  Per the Mathcad Prime documentation for LRESULT:

 

The arrays and scalars that you can pass in and out of a DLL file are always complex, and arrays are always two dimensional. You can access the real and complex parts of any scalar input value by using the ParamName->real and ParamName->imag members. Similarly, you can access the real and complex parts of any input array by using the Array->hReal and Array->hImag members. Arrays are indexed by column, then row, as opposed to the order of indices inside PTC Mathcad (by row, then column). All arrays are assumed to have two dimensions. To reference a vector, you set the first array index (column) to 0, for example:
• ArrayName->hReal[0][row], or
• ArrayName->hImag[0][row]
 
Your code is over-running the dimensions of the y matrix in the column direction.  Just swap your indexes to:
 
y->hReal[0][i] = x->real * x->real;
 
I compiled your code and it works with this fix.
 
P.S. You can always drag and drop a file as an attachment to a post.

2 replies

Community Moderator
July 19, 2024

Hi @DM_10631844,

Thank you for your question. 

Your post appears well documented but has not yet received any response. I am replying to raise awareness. Hopefully, another community member will be able to help.

Regards,

Vivek N
Community Moderation Team.

JeffH116-PearlAnswer
16-Pearl
July 19, 2024

There's just one problem here, the indices on the return vector/matrix are switched.  Per the Mathcad Prime documentation for LRESULT:

 

The arrays and scalars that you can pass in and out of a DLL file are always complex, and arrays are always two dimensional. You can access the real and complex parts of any scalar input value by using the ParamName->real and ParamName->imag members. Similarly, you can access the real and complex parts of any input array by using the Array->hReal and Array->hImag members. Arrays are indexed by column, then row, as opposed to the order of indices inside PTC Mathcad (by row, then column). All arrays are assumed to have two dimensions. To reference a vector, you set the first array index (column) to 0, for example:
• ArrayName->hReal[0][row], or
• ArrayName->hImag[0][row]
 
Your code is over-running the dimensions of the y matrix in the column direction.  Just swap your indexes to:
 
y->hReal[0][i] = x->real * x->real;
 
I compiled your code and it works with this fix.
 
P.S. You can always drag and drop a file as an attachment to a post.
16-Pearl
July 20, 2024

@DM_10631844 - Please accept the above as the answer if appropriate.

 

I've attached my version of your code basing it on the standard template provided by PTC.  I had to change the extension from ".C" to ".txt" to post it here.  you'll need to change it back to use it.  It gives the following result in Mathcad Prime:

JeffH1_0-1721485643640.png

 

 

 

16-Pearl
July 20, 2024

Let's try again.   I'll zip it.