mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 03:30:34 +08:00
update fixing bug #5599
This commit is contained in:
parent
03e7b71707
commit
ed0065266e
@ -2530,21 +2530,14 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters )
|
||||
double old_num_im = num.im;
|
||||
|
||||
num.re = old_num_re*old_num_re + old_num_im*old_num_im;
|
||||
Mat num_re_arr = (Mat_<double>(1,1) << num.re);
|
||||
cv::sqrt(num_re_arr, num_re_arr);
|
||||
num.re = num_re_arr.at<double>(0, 0);
|
||||
num.re = std::sqrt(num.re);
|
||||
num.re += old_num_re;
|
||||
num.im = num.re - old_num_re;
|
||||
num.re /= 2;
|
||||
num_re_arr.at<double>(0, 0) = num.re;
|
||||
cv::sqrt(num_re_arr, num_re_arr);
|
||||
num.re = num_re_arr.at<double>(0, 0);
|
||||
num.re = std::sqrt(num.re);
|
||||
|
||||
Mat num_im_arr = (Mat_<double>(1,1) << num.im);
|
||||
num.im /= 2;
|
||||
num_im_arr.at<double>(0, 0) = num.re;
|
||||
cv::sqrt(num_im_arr, num_im_arr);
|
||||
num.im = num_im_arr.at<double>(0, 0);
|
||||
num.im = std::sqrt(num.im);
|
||||
if( old_num_re < 0 ) num.im = -num.im;
|
||||
}
|
||||
}
|
||||
|
38
samples/cpp/polynominal_equations.cpp
Normal file
38
samples/cpp/polynominal_equations.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* solves equations x^4 - x^2 = 0, and x^2 - 2x + 1 = 0
|
||||
*/
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cv::Mat coefs = (cv::Mat_<float>(1,5) << 0, 0, -1, 0, 1 );
|
||||
std::cout << "x^4 - x^2 = 0\n\n" << "Coefficients: " << coefs << "\n" << std::endl;
|
||||
cv::Mat r;
|
||||
|
||||
double prec;
|
||||
prec = cv::solvePoly(coefs, r);
|
||||
std::cout << "Preciseness = " << prec << std::endl;
|
||||
std::cout << "roots after 1000 iterations:\n" << r << "\n" << std::endl;
|
||||
|
||||
prec = cv::solvePoly(coefs, r, 9999);
|
||||
std::cout << "Preciseness = " << prec << std::endl;
|
||||
std::cout << "roots after 9999 iterations:\n" << r << "\n" << std::endl;
|
||||
|
||||
std::cout << "\n---------------------------------------\n" << std::endl;
|
||||
|
||||
coefs = (cv::Mat_<float>(1,3) << 1, -2, 1 );
|
||||
std::cout << "x^2 - 2x + 1 = 0\n\n" << "Coefficients: " << coefs << "\n" << std::endl;
|
||||
|
||||
prec = cv::solvePoly(coefs, r);
|
||||
std::cout << "Preciseness = " << prec << std::endl;
|
||||
std::cout << "roots after 1000 iterations:\n" << r << "\n" << std::endl;
|
||||
|
||||
prec = cv::solvePoly(coefs, r, 9999);
|
||||
std::cout << "Preciseness = " << prec << std::endl;
|
||||
std::cout << "roots after 9999 iterations:\n" << r << "\n" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user