Question: CodeGeneration. Outputting Multiple Entries?

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]);

 

 

Please Wait...