Products & Services Solutions Academia Support User Community Company

Learn more about Symbolic Math Toolbox   

ccode - C code representation of symbolic expression

Syntax

ccode(s)
ccode(s,'file',fileName)

Description

ccode(s) returns a fragment of C that evaluates the symbolic expression s.

ccode(s,'file',fileName) writes an "optimized" C code fragment that evaluates the symbolic expression s to the file named fileName. "Optimized" means intermediate variables are automatically generated in order to simplify the code.

Examples

The statements

syms x
f = taylor(log(1+x));
ccode(f) 

return

  t0 = x-(x*x)*(1.0/2.0)+(x*x*x)*(1.0/3.0)-(x*x*x*x)*(1.0/4.0)+(x*x*x*x*x)*(1.0/5.0);

The statements

H = sym(hilb(3));
ccode(H)

return

  H[0][0] = 1.0;
  H[0][1] = 1.0/2.0;
  H[0][2] = 1.0/3.0;
  H[1][0] = 1.0/2.0;
  H[1][1] = 1.0/3.0;
  H[1][2] = 1.0/4.0;
  H[2][0] = 1.0/3.0;
  H[2][1] = 1.0/4.0;
  H[2][2] = 1.0/5.0;

The statements

syms x
z = exp(-exp(-x));
ccode(diff(z,3),'file','ccodetest');

return a file named ccodetest containing the following:

  t2 = exp(-x);
  t3 = exp(-t2);
  t0 = t3*exp(x*(-2.0))*(-3.0)+t3*exp(x*(-3.0))+t2*t3;

See Also

fortran, latex, matlabFunction, pretty

Generating Code from Symbolic Expressions

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS