Using the C++ Math Library    

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

The roots() function finds the roots of a polynomial. The M-file roots.m contains the source of the roots() function. This example shows how to translate roots.m into C++. The translation keeps the C++ function as similar as possible to the M-function, primarily to demonstrate how easy it is to write MATLAB-like code in C++. This means that the C++ code is not as efficient as it could be, but the example does show that the C++ code is as simple to write as a MATLAB M-file.


 Renaming Functions to Avoid a Name Conflict The M-File roots() Function