[Date Index]
[Thread Index]
[Author Index]
Re: Solved: Factor/Simplify set of complex expressions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg116682] Re: Solved: Factor/Simplify set of complex expressions
*From*: Oliver Ruebenkoenig <ruebenko at wolfram.com>
*Date*: Thu, 24 Feb 2011 06:20:20 -0500 (EST)
*References*: <1268716D-B201-475C-962B-E1F813BCD634@gmail.com>
On Wed, 23 Feb 2011, Enrique Fernández Perdomo wrote:
> Hello all,
>
> Given a function and its derivatives, it is possible to obtain an optimized expression to compute all of them using:
> Experimental`OptimizeExpression
>
> Here it is a synthetic example:
> z = 1 - Tanh[(y - B[t] Cos[k (x - c t)])/Sqrt[1 + (k B[t] Sin[k (x - c t)])^2]];
> res = Table[D[z, {x, i}, {y, j}], {i, 1, 2}, {j, 1, 2}] // Simplify
> Experimental`OptimizeExpression[res]
>
> Notice that the call to Simplify takes some time depending on the original function, but if not used the resulting optimized expression would be larger. So, you might omit Simplify or use a simpler function, like:
> z = b (1 - f[x, y, t]^2);
>
> Thanks to Oliver Ruebenkoenig.
>
> Best regards,
> Enrique
Enrique,
I think here is a better way seen that you want to generate a c code.
Proceed as you do, once you have the result res call compile on that -
make a compiled function.
cf=Compile[{{balh,blah,blah}}, Evaluate[res]]
The compiler internally calls Experimental`OptimizeExpression[res]
Then, you can use Export to export the compiled function to C; then you'd
have to write a C wrapper to call that function.
Have a look at
CCodeGenerator/tutorial/Examples#659427467
Hth,
Oliver
Prev by Date:
**Re: weibull plot on weibull scaled paper**
Next by Date:
**Re: Blending in DiscretePlot**
Previous by thread:
**Solved: Factor/Simplify set of complex expressions**
Next by thread:
**Pattern Matching Question**
| |