Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Greetings, I tried to create custom functions in mathcad but I was able to do it, however I wanted to create that function fc and fc1 and I couldn't, I get an error message I understand how to compile and tried other functions but when I go to do it with results of vectors and matrices I have this problem here I attach the code in C only for the fc function, could you help me how to create both custom functions please?
1
1
Use subscript rather than function notation when asking for components:
More like:
1
#include "mcadincl.h"
#define INTERRUPTED 1
#define INSUFFICIENT_MEMORY 2
#define MUST_BE_REAL 3
#define NUMBER_OF_ERRORS 3
// table of error messages
char * myErrorMessageTable[NUMBER_OF_ERRORS] =
{ "interrupted",
"insufficient memory",
"must be real"
};
// this code executes the operation
LRESULT CreateVectorWithXSquare(COMPLEXARRAY * const Vector, LPCCOMPLEXSCALAR Scalar)
{
unsigned int i;
// check that the scalar argument is real
if (Scalar->imag != 0.0)
return MAKELRESULT(MUST_BE_REAL, 1);
// allocate memory for the vector
if (!MathcadArrayAllocate(Vector, 4, 1, TRUE, FALSE))
return INSUFFICIENT_MEMORY;
// fill the vector with the square of the scalar
for (i = 0; i < 4; i++) {
if (isUserInterrupted()) {
MathcadArrayFree(Vector);
return INTERRUPTED;
}
Vector->hReal[i][0] = Scalar->real * Scalar->real;
}
// normal return
return 0;
}
// fill out a FUNCTIONINFO structure with the information needed for registering the function with Mathcad
FUNCTIONINFO fc2 =
{
"fc2",
"x",
"returns a vector of length 4 with the square of the scalar x",
(LPCFUNCTION)CreateVectorWithXSquare,
COMPLEX_ARRAY,
1,
{ COMPLEX_SCALAR }
};
// DLL entry point code
BOOL WINAPI _CRT_INIT(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved);
BOOL WINAPI DllEntryPoint(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
if (!_CRT_INIT(hDLL, dwReason, lpReserved))
return FALSE;
if (CreateUserErrorMessageTable(hDLL, NUMBER_OF_ERRORS, myErrorMessageTable))
CreateUserFunction(hDLL, &fc2);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
if (!_CRT_INIT(hDLL, dwReason, lpReserved))
return FALSE;
break;
}
return TRUE;
}
#undef INTERRUPTED
#undef INSUFFICIENT_MEMORY
#undef MUST_BE_REAL
#undef NUMBER_OF_ERRORS
#define INTERRUPTED 1
#define INSUFFICIENT_MEMORY 2
#define MUST_BE_REAL 3
#define NUMBER_OF_ERRORS 3
#include "mcadincl.h"
#define INTERRUPTED 1
#define INSUFFICIENT_MEMORY 2
#define MUST_BE_REAL 3
#define NUMBER_OF_ERRORS 3
// table of error messages
char * myErrorMessageTable[NUMBER_OF_ERRORS] =
{ "interrupted",
"insufficient memory",
"must be real"
};
// this code executes the operation
LRESULT CreateRowMatrixWithXSquare(COMPLEXARRAY * const Matrix, LPCCOMPLEXSCALAR Scalar)
{
unsigned int i;
// check that the scalar argument is real
if (Scalar->imag != 0.0)
return MAKELRESULT(MUST_BE_REAL, 1);
// allocate memory for the matrix
if (!MathcadArrayAllocate(Matrix, 1, 4, TRUE, FALSE))
return INSUFFICIENT_MEMORY;
// fill the row with the square of the scalar
for (i = 0; i < 4; i++) {
if (isUserInterrupted()) {
MathcadArrayFree(Matrix);
return INTERRUPTED;
}
Matrix->hReal[0][i] = Scalar->real * Scalar->real;
}
// normal return
return 0;
}
// fill out a FUNCTIONINFO structure with the information needed for registering the function with Mathcad
FUNCTIONINFO fc1 =
{
"fc1",
"x",
"returns a 1x4 row matrix with the square of the scalar x",
(LPCFUNCTION)CreateRowMatrixWithXSquare,
COMPLEX_ARRAY,
1,
{ COMPLEX_SCALAR }
};
// DLL entry point code
BOOL WINAPI _CRT_INIT(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved);
BOOL WINAPI DllEntryPoint(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
if (!_CRT_INIT(hDLL, dwReason, lpReserved))
return FALSE;
if (CreateUserErrorMessageTable(hDLL, NUMBER_OF_ERRORS, myErrorMessageTable))
CreateUserFunction(hDLL, &fc1);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
if (!_CRT_INIT(hDLL, dwReason, lpReserved))
return FALSE;
break;
}
return TRUE;
}
#undef INTERRUPTED
#undef INSUFFICIENT_MEMORY
#undef MUST_BE_REAL
#undef NUMBER_OF_ERRORS
#define INTERRUPTED 1
#define INSUFFICIENT_MEMORY 2
#define MUST_BE_REAL 3
#define NUMBER_OF_ERRORS 3
The first code is fc2, it doesn't work, it gives an error and the 2nd is fc1, it works fine in C++