Items tagged with codegeneration codegeneration Tagged Items Feed

Hi Mapleprimers,

I'm using CodeGeneration to convert a procedure I obtained with unapply() into a Matlab function.  I'm having problems getting the outputting function to run correctly in Matlab.  I'm going to dynamically generating equations, so directly editing the Matlab code won't work here.  I'm having problems getting any output in Matlab.  Here is the code I'm working on:  Series_addGear_codegen.mw

Ideally I would like output in a matrix.  I've tried putting the unapplied procedure in another procedure, but the CodeGeneration doesn't work.

This is the maple output from the function:

unapp(1,2,3,4,5);
{BAT_A = -2.267032891, BAT_V = 271, EM2_A = .4615464218, EM2_P = 125.0790803, EM2_T = -1, EM2_V = 271, EM2_W = 2, GBa_T = 12, GBa_W = 5/3, GBb_T = -4, GBb_W = 5, GEN_A = 1.805486469, GEN_P = 489.2868330, GEN_T = -12, GEN_V = 271, GEN_W = 5/3, ICE_mdot_g = 20}

Since I'll know the order of variables, I want the Matlab function to output:

[-2.267032891,  271,  .4615464218,  125.0790803,  -1, ...]

This is the output after putting the Matlab function in Matlab:

>> unapp(1, 1, 1, 1, 1)
Undefined function or variable 'BAT_A'.

Error in unapp (line 39)
unappreturn = unique([BAT_A == -t35 / 0.271e3 - t73 / 0.271e3 BAT_V == 271 EM2_A == t35 /
0.271e3 EM2_P == t35 EM2_T == -FD_T EM2_V == 271 EM2_W == FD_W GBa_T == t44 GBa_W == t41 GBb_T
== -ICE_T GB

This is the Matlab code that is generated by Maple 18:

MCode:=CodeGeneration[Matlab](unapp, declare = [FD_T::float, FD_W::float, GB_R::float, ICE_T::float, ICE_W::float],defaulttype=float,optimize,defaulttype = numeric);
Warning, could not preprocess. Found `abs` or similar in the 'While'/'For' conditions.
Warning, procedure/module options ignored
function unappreturn = unapp(FD_T, FD_W, GB_R, ICE_T, ICE_W)
t2 = 0.1e1 * FD_T * FD_W;
t5 = abs(FD_W);
t7 = abs(FD_T);
t9 = t5 ^ 2;
t13 = t7 ^ 2;
t15 = t9 * t5;
t21 = t13 * t7;
t23 = t9 ^ 2;
t31 = t13 ^ 2;
t33 = 0.1483000000e3 - 0.4267000000e1 * t5 - 0.1277000000e2 * t7 + 0.3640000000e-1 * t9 - 0.1160000000e1 * t5 * t7 + 0.2580000000e0 * t13 - 0.1181000000e-3 * t15 + 0.5994000000e-3 * t9 * t7 - 0.1171000000e-3 * t5 * t13 - 0.1739000000e-2 * t21 + 0.1245000000e-6 * t23 - 0.1200000000e-5 * t15 * t7 + 0.1584000000e-5 * t9 * t13 - 0.4383000000e-6 * t5 * t21 + 0.2947000000e-5 * t31;
if (-t2 == 0.0e0)
t35 = 0.0e0;
elseif (-t2 < 0.0e0)
t35 = t33;
else
t35 = -t33;
end
t36 = ICE_T * ICE_W;
t37 = 0.1e1 * t36;
t41 = ICE_W / GB_R;
t42 = abs(t41);
t44 = ICE_T * GB_R;
t45 = abs(t44);
t47 = t42 ^ 2;
t51 = t45 ^ 2;
t53 = t47 * t42;
t59 = t51 * t45;
t61 = t47 ^ 2;
t69 = t51 ^ 2;
t71 = 0.5280000000e-11 - 0.3849000000e-13 * t42 + 0.7190000000e2 * t45 + 0.1168000000e-15 * t47 - 0.1296000000e1 * t42 * t45 - 0.2489000000e1 * t51 - 0.1451000000e-18 * t53 - 0.1326000000e-3 * t47 * t45 + 0.8141000000e-2 * t42 * t51 + 0.4539000000e-2 * t59 + 0.6325000000e-22 * t61 + 0.2091000000e-6 * t53 * t45 - 0.3455000000e-5 * t47 * t51 - 0.2499000000e-4 * t42 * t59 + 0.5321000000e-4 * t69;
if (-t37 == 0.0e0)
t73 = 0.0e0;
elseif (-t37 < 0.0e0)
t73 = t71;
else
t73 = -t71;
end
unappreturn = unique([BAT_A == -t35 / 0.271e3 - t73 / 0.271e3 BAT_V == 271 EM2_A == t35 / 0.271e3 EM2_P == t35 EM2_T == -FD_T EM2_V == 271 EM2_W == FD_W GBa_T == t44 GBa_W == t41 GBb_T == -ICE_T GBb_W == ICE_W GEN_A == t73 / 0.271e3 GEN_P == t73 GEN_T == -t44 GEN_V == 271 GEN_W == t41 ICE_mdot_g == t36]);

 

 

Hello!

 

I am trying to create a Fortran routine that creates and populates a large 2D array, using Maple's codegen or CodeGeneration capabilities. I would like Maple to create the Fortran code so that the column-major ordering is respected: I would like Maple to populate mat(1,1), mat(2,1), mat(n,1) before moving on to mat(1,2)... Unfortunately, codegen and CodeGeneration seem to only produce row-major code.

Any idea on how to proceed, or an option of the code generation that I would have missed?

 

Thanks for your help!

Etienne

Hello.
I'm new to Maple, so my question could appear idiotic. But, anyway. :-)

I want to understand the restrictions of code generation in Maple.
What functions could I convert to code?
Only listed in "Translation of Functions" block in this link?
http://www.maplesoft.com/support/help/MapleSim/view.aspx?path=CodeGeneration/General/TranslationDetails

For example, I've found this post - http://www.mapleprimes.com/posts/36616-Dynamic-Programming-In-Maple 

Could functions "Maximize" and "diff" be converted to Java, VB or something or not? If yes, how?

Thanks anyway. :-)

Dear all,

I compute a 12,3 matrix in Maple and when I try to generate matlab code with optimization on, the result is a 36 element vector. Also, it warns me as "Warning, cannot resolve types, reassigning t15's type" and "Warning, cannot translate list". When I tried it without optimize=false it yields correct result but the file size is big. I have obtained the correct optimized resutls using Maple 13 before and hence i guess theres somthing to do with maple 17. Any...

Dear all

i am writing some differential equations with Maple. I'd like now to generate the Matlab code and let them run. Unfortunately I need the closed form but Maple does not distinguish (at first sight, of course) between time functions and parameters. But what in Maple is a time function, will be an array in Matlab. Unfortunately in Matlab environment the array product is carried out by the meaning of the element-by-element command: ".* " .

Using CodeGeneration[Matlab...

I have a Matrix 'A' in maple with symbolic entries and I need to use that Matrix in matlab M file. The symbols with in 'A' are already initialized in M file.

How is this possible?

For Matrices 'A' of small dimension, I can use the codegeneration package to convert 'A' to Matlab Matrix and then copy paste.

But for matrices of 1000x1000, lets say, does not seem as a option.

 

I need more help with code please!

A box of candy hearts contains 52 hearts, of which 19 are white, 10 are tan, 7 are pink, 3 are purple, 5 are yellow, 2 are orange, and 6 are green. If you select 9 pieces randomly without replacement, what is the probability that A_3 of the 9 are white, and B_3 of the 9 are white, 2 are tan 1 is pink and 1 is yellow and 2 are green

19 Whites in the pack / 52 hearts in the pack = .3654 possibility of picking a white from 1 draw.

How to convert Maple code to Matlab ?

comment je doiy faire pour convertir mon code Maple en Matlab?

merci d'avance pour votre aide.

Cordialement.

Hi

How can i convert maple file to matlab ?

I want to extend the Maple CodeGeneration[C] by a handler for the piecewise function (no idea why it is not included).
To this end I did:

    with(CodeGeneration):
    with(LanguageDefinition):
    
    LanguageDefinition:-Define("NewC", extend="C",
        AddFunction("piecewise", anything::numeric,
            proc()

Hello,

Can someone explain to me why when "x:=vector(2):" is used in the code below, the file "test_file.c" is generated correctly, while when "x := Vector(2,symbol=v):" is used, there is an error:

Error, (in codegen/makestat) symbol or symbol::type or symbol:=expression expected in parameter list

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

with(LinearAlgebra):
with(codegen, C, makeproc):

#x := Vector(2,symbol=v):

restart; with(plots); Eq1 := diff(f(eta), `$`(eta, 3))-(diff(f(eta), eta))^2+m*f(eta)*(diff(f(eta), `$`(eta, 2)))-(M^2+lambda*P)*(diff(f(eta), eta)) = 0; Eq2 := diff(theta(eta), `$`(eta, 2))+m*pr*f(eta)*(diff(theta(eta), eta))-lambda1*pr*theta(eta)*(diff(f(eta), eta)) = 0; bcs1 := f(0) = s, (D(f))(0) = -1, (D(f))(10) = 1; pr := .72; M := 1; m := 2; lambda := 1; lambda1 := 1; bcs2 := theta(10) = 0, theta(0) = 1; L := [0.5e-1, .1, .2, .4, .6, .8, 1, 5, 10, 20]; for k to 10 do R := dsolve...

 

I execue flow command,but it doesnot generate;

how i fix it?

 

> with(CodeGeneration);



> m:=diff(theta1(t),t);

                     
> Matlab(m);

Warning, the function names {diff, theta1} are not recognized in the target language

cg0 = diff(theta1(t), t);



I am using the code generation package to generate fortran 90 code.   In a Maple module I have a procedure that uses "CodeGeneration[Fortran]" to turn a symbolic matrix into a subroutine in Fortran; i.e., given an n-vector q the Fortran subroutine will return an n by n matrix.  However, since Maple's "Fortran" command does not support Fortran 90 I have utilized the StringTools[RegSubs] to alter the line continuation differences between fortran 77 and fortran...

I keep getting this error although the code is running fine in maple 14 , Help is greatly appreciated Thanks alot

> restart; with(LinearAlgebra);
> A[0] := Vector(3, {(1) = 0, (2) = 0, (3) = -g});
> type(a[0], Vector);
                             false
> omega[0] := Vector(3, {(1) = 0, (2) = 0, (3) = 0});

1 2 Page 1 of 2