0
$\begingroup$

This question already has an answer here:

I have written mathematica file that does manipulations on a certain set of points. I would like to access code that someone else has written for a least square fit in C++. How do I access this C++ in mathematica?

Some specifics about the code: The least square fit code is a function that accesses a .cpp file and two different .h files. It is a void function that takes in a vector of points, the point itself, and an integer, each called by reference.

I make this specific because I am a novice in coding in c++. I have seen in another post someone say that they have :

I think we have these:

MathLink communication through pipes/files LibraryLink

I do not have any of those things, nor do I know what they are. Can someone explain how a novice like myself can handle this situation.

Also, from what I saw from other posts, the function I have to access is much more complicated. It looks something like:

void function1(vectorFoo &thing, Foo &variable1, int64_t &variable2) {

    stuff happens here
}

(the the first argument of the function is a vector that takes in Foo between "<" and ">" but that formatting won't let me show that. that's why I wrote "vectorFoo")

this function accesses other functions,call them "function2", "function3", and other named variables (if that is the right technical term...like I said, I don't know much c++) from three files. so even if I call this file, will I have to worry about calling the other three files from which it draws? Please help!

$\endgroup$

marked as duplicate by Szabolcs, C. E., MarcoB, Jens, m_goldberg Jul 7 '15 at 0:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Regardless of the accepted answer there, today, generally the best way is LibraryLink. $\endgroup$ – Szabolcs Jul 6 '15 at 20:32
  • 2
    $\begingroup$ You're aware that Mathematica knows all about least squares fits (and other types of fits)? $\endgroup$ – Sjoerd C. de Vries Jul 6 '15 at 20:34
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Jul 6 '15 at 20:36
  • 2
    $\begingroup$ "They are not suitable for my purposes." - can you explain why? $\endgroup$ – J. M. will be back soon Jul 7 '15 at 12:54
  • 2
    $\begingroup$ The following one-liner with a list of your coordinate pairs as input in the variable pts finds the circle parameters for you: NMinimize[{((#1 - mx)^2 + (#2 - my)^2 - r^2)^2 & @@@ pts // Total, mx > 0 && my > 0 && r > 0}, {mx, my, r}] $\endgroup$ – Sjoerd C. de Vries Jul 7 '15 at 14:38

Browse other questions tagged or ask your own question.