C_R

1960 Reputation

19 Badges

5 years, 281 days

MaplePrimes Activity


These are questions asked by C_R

I have started to use CodeGeneration[C] instead of codegen[C] (depreciated). In the attached example not all variables and parameters of a C function are declared as double, although the default value is double.

If this is by design:

How can I force double without going back to codegen[C] or manual declaration of each item?

C_code_generation_with_CodeGeneration.mw

From an equation list originating from code optimization, a set of parameters and intermediate variables `tx` (where x is an integer) can be extracted.

{la, ra, rb, t, t10, t11, t12, t13, t15, t17, t18, t19, t21, t23, t24, t25, t26, t27, t28, t31, t32, t33, t34, t35, t36, t37, t39, t41, t42, t43, t44, t45, t46, t48, t49, t5, t50, t52, t53, t54, t55, t56, t57, t58, t59, t61, t62, t63, t64, t65, t67, t68, t69, t7, t70, t9, xa, za}

{la, ra, rb, t, t10, t11, t12, t13, t15, t17, t18, t19, t21, t23, t24, t25, t26, t27, t28, t31, t32, t33, t34, t35, t36, t37, t39, t41, t42, t43, t44, t45, t46, t48, t49, t5, t50, t52, t53, t54, t55, t56, t57, t58, t59, t61, t62, t63, t64, t65, t67, t68, t69, t7, t70, t9, xa, za}

(1)

 

To extract from this list the intermediate variables for further processing I do

with(StringTools); intermediates := NULL; for i in {la, ra, rb, t, t10, t11, t12, t13, t15, t17, t18, t19, t21, t23, t24, t25, t26, t27, t28, t31, t32, t33, t34, t35, t36, t37, t39, t41, t42, t43, t44, t45, t46, t48, t49, t5, t50, t52, t53, t54, t55, t56, t57, t58, t59, t61, t62, t63, t64, t65, t67, t68, t69, t7, t70, t9, xa, za} do if `and`(is(FirstFromLeft(convert(i, string), t) = 1), type(parse(convert(i, string)[2]), integer)) then intermediates := intermediates, i end if end do

{intermediates}

{t10, t11, t12, t13, t15, t17, t18, t19, t21, t23, t24, t25, t26, t27, t28, t31, t32, t33, t34, t35, t36, t37, t39, t41, t42, t43, t44, t45, t46, t48, t49, t5, t50, t52, t53, t54, t55, t56, t57, t58, t59, t61, t62, t63, t64, t65, t67, t68, t69, t7, t70, t9}

(2)

NULL

Quite some code for a little task. Can this be done more efficiently?

Download extract_tx.mw

To make the "Simple External Code Function" example of the tutorial work, an external complier is required.

in MapleSim:-CreateDataRecord) invalid input: dsolve/numeric/ToExternal:-AddTempFile expects its 1st argument, f, to be of type string, but received [[["f1", 1864151924736]]] (3.597s)

Update:

help(Setup, Compiler) in Maple 2022 provides a link to supported compilers, which are Visual Studio 2017 and 2019.

In the list of available downloads there is no mention of "Express Edition". Which of the packages can be installed alternatively?

A "while" ago this was possible by commands. E.g.:

(from https://www.youtube.com/watch?v=uaQh_bXcIGA)

I consulted the help pages for Export and CodeGeneration options, but could not find anything suitable to generate a C code file.

Did I overlook something or searched for the wrong help pages?

If such options no longer exist, what is the preferred way to transfer C code from Maple to MapleSim?

Am I supposed to copy, paste & save with a third party editor? If I do so for a C code generated from a Maple procedure (generated with makeproc), I get

A complete example that works in 2022 versions would be helpfull. The tutorial "6.6 Tutorial 6: Using the External C Code/DLL Custom Component App" unfortuneately does not include code generated by Maple that can be imported, compiled, simulated and verified against a MapleSim model as in the example from youtube (which is still very instructive by the way). 

Example: Assume expressions assigned to names

xa, xb, xc := y = x, y = x^2, x = x^3

y = x, y = x^2, x = x^3

(1)

where you want to apply a command (rhs in this example) to all names fitting to a certain scheme (here a and c)

seq(cat(x, i), i = [a, c])

xa, xc

(2)

`~`[rhs]([xa, xc])[]

x, x^3

(3)

Combining (2) and (3) in one line

seq(rhs(cat(x, i)), i = [a, c])

Error, invalid input: rhs received xa, which is not valid for its 1st argument, expr

 

throws an error. Although xa evaluates to an equation

rhs(xa)

x

(4)

and

whattype(cat(x, a))

`=`

(5)

seems to do the same.
I have not worked out what the xa is that rhs is receiving in the one line statement (see error).
Since rhs returns xa it does not look like a delayed evaluation.

 

Besides an explanation of what is going on, I'm interested if there is a way to debug what is passed to rhs?

Download cat_in_nested_statement.mw

First 15 16 17 18 19 20 21 Page 17 of 24