<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Petre,<div><br></div><div>It sounds like what you want is to curry a function f(x, a) into a function g(x) that will then get passed to your root-finder. See:</div><div><a href="http://stackoverflow.com/questions/152005/how-can-currying-be-done-in-c">http://stackoverflow.com/questions/152005/how-can-currying-be-done-in-c</a></div><div><br></div><div>Best,</div><div><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;  "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Hao Ye</div><div><a href="mailto:hye@ucsd.edu">hye@ucsd.edu</a></div></div></span></span>
</div>
<br><div><div>On Apr 8, 2014, at 8:36 AM, Petre Caraiani <<a href="mailto:petre.caraiani@gmail.com">petre.caraiani@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br><br><br>I don't know how to change the parameters of the function. The Brent routine finds the root of a function depending just on x. I know how to pass a vector between R and C, but I want to pass it to the function, while having the function depending on variable x only.<div>

<br><br>On Tuesday, April 8, 2014, Dirk Eddelbuettel <<a href="javascript:_e(%7B%7D,'cvml','edd@debian.org');" target="_blank">edd@debian.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
On 8 April 2014 at 16:41, Petre Caraiani wrote:<br>
| I have a code in C which computes the root of a function using the Brent<br>
| algorithm. The code is attached below. I provided the full code but you can<br>
| focus on the function definition and the main program. I can call this program<br>
| from R. What I am interested in is looping over the parameters of the defined<br>
| function. For example, passing an array a to the C program and computing the<br>
| root of the function: (x*x-a[i]/2) for each entry in vector a.<br>
<br>
I don't follow. Excactly what is issue you are having?  How to pass a vector<br>
from R to C++ and back?  How to access elements in the vector?<br>
<br>
You seem to have all relevant elements in place. Have a look at posted<br>
examples, eg on the Rcpp Gallery, or examples included in the Rcpp or other<br>
packages.<br>
<br>
Dirk<br>
<br>
--<br>
Dirk Eddelbuettel | <a>edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com/" target="_blank">http://dirk.eddelbuettel.com</a><br>
</blockquote></div>
<br>
_______________________________________________<br>Rcpp-devel mailing list<br><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</blockquote></div><br></div></body></html>