| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Symbolic Math Toolbox |
| Contents | Index |
| Learn more about Symbolic Math Toolbox |
ccode(s)
ccode(s,'file',fileName)
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.
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;
fortran, latex, matlabFunction, pretty
Generating Code from Symbolic Expressions

See how symbolic computations can help you find analytical solutions to math and engineering problems.
Get free kit| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |