Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Compile result of Solve command' topicStudent Support Forum > General > "Compile result of Solve command"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
jf
07/05/13 4:35pm

You need to use the output of Solve (a Rule) to derive an expression for a.

In[1]:= eqn=a+b+c==0 ;
res=Solve[eqn,a]
Out[2]= {{a->-b-c}}

In[3]:= temp = a /. First[res]
Out[3]= -b-c

In[4]:= cfun=Compile[{b,c},Evaluate[temp]]
Out[4]= CompiledFunction[{b,c}, -b-c,-CompiledCode-]

In[5]:= cfun[3.,4.]
Out[5]= -7.

Compiling to C code is non-trivial.

http://reference.wolfram.com/mathematica/tutorial/GeneratingCAndFortranExpressions.html

http://reference.wolfram.com/mathematica/CCodeGenerator/tutorial/Overview.html



URL: ,

Subject (listing for 'Compile result of Solve command')
Author Date Posted
Compile result of Solve command Axel Lachmeyer 07/05/13 03:45am
Re: Compile result of Solve command jf 07/05/13 4:35pm
Re: Re: Compile result of Solve command Axel Lachmeyer 07/12/13 06:17am
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic