# Maple stored variable to be read into Matlab

I have a a function $f(k)$ (calculated in Maple) which is huge and stored in a variable called 'sum' on my drive (with the help of 'save' command in Maple). Since the function is huge, Maple is unable to plot it and is taking endless time. Thus, I want to read the variable 'sum' into Matlab and plot it. I am unable to also just copy paste as the function is really big. I have searched around but am unable to find a solution. Can somebody help me out?

• Is 'sum' an expression or a procedure? What sort of operations does it entail? (Just simple algebra, or are there e.g. transcendental functions?) And on an unrelated note, if you unprotect 'sum' in maple and reassign something to it that's not a procedure for summation, you're lucky if you still get useful answers from maple... – Erik P. Oct 27 '14 at 13:53
• 'sum' is an expression and only has polynomial functions. – zynga Oct 27 '14 at 13:59

You can use the CodeGeneration package to do this. It allows to translate to different languages, being Matlab one of those.

A simple example here:

with(CodeGeneration);
suma := sum(sin(n*x)/factorial(n), n = 0 .. 10);


then

Matlab(suma)


cg3 = sin(x) + sin(0.2e1 * x) / 0.2e1 + sin(0.3e1 * x) / 0.6e1 + sin(0.4e1 * x) / 0.24e2 + sin(0.5e1 * x) / 0.120e3 + sin(0.6e1 * x) / 0.720e3 + sin(0.7e1 * x) / 0.5040e4 + sin(0.8e1 * x) / 0.40320e5 + sin(0.9e1 * x) / 0.362880e6 + sin(0.10e2 * x) / 0.3628800e7;