Using the C++ Math Library    

The M-File roots() Function

The C++ example_roots() function is a translation of the M-file roots() function. For purposes of comparison, roots.m is reproduced below. Not counting the comments or the main routine, the C++ code is only four lines longer than the M-code. Two of the extra lines are used for declaring variables and the other two for including header files.

MATLAB M-file code for roots():


 Example Program: Rewriting roots.m in C++ (ex8.cpp) The C++ roots() Function