Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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. MATLAB® generates intermediate variables as a lowercase letter t followed by an automatically generated number, for example t32.

Examples

The statements

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

return

ans =
  1×85 char array
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

 ans =
  1×184 char array
  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;

Introduced before R2006a

Was this topic helpful?