コード例 #1
0
ファイル: 13.c プロジェクト: yabeenico/psp
/*main関数。*/
int main(void){
	int i;
	double x;

	/*s(x) : 標準シグモイド関数を表示。*/
	printf("s(x) = 1 / {1 + exp(-x)}\n");

	/*s(x)が0.1~0.9となるような解xをそれぞれえ求める。*/
	for(i = 1; i < 10; i++){
		/*xの初期値を0とし、s(x)=0.iの解をニュートン法で得る。*/
		x = Newton(s, ds, i / 10.0, 0);
		/*求めた解をs(x)に代入し、解が正しいか確認。*/
		printf("s(%f) = %f\n", x, s(x));
	}

	printf("\n");
	
	/*f(x) : 最小値を求めたい関数を表示。*/
	printf("f(x) = 3x^4 - 4x^3 - 12x^2 + 32\n");
	/*xの初期値を3とし、f(x)の傾きが0となるx座標をニュートン法で求める。*/
	x = Newton(df, ddf, 0, 3);
	/*xにはf(x)の最小値の候補のx座標が入っている。*/
	/*求めたxをf(x)に代入し最小値となっているか確認。*/
	printf("f(%f) = %f (min)\n", x, f(x));

	return 0;
}
コード例 #2
0
int main(int argc, char const *argv[])
{
	double a;
	printf("%fl\n", Newton(10));
	a=Newton(10);
	return 0;
}
コード例 #3
0
ファイル: Solucion.c プロジェクト: PraderioM/Frikientregues
int main(){
	printf("Calculando la longitud de la elipse obtenemos como resultado\nL=%.10g\n\n", L);
	printf("El punto encontrado aproximando las integrales mediante integracion de polinomios ");
	/*Mostramos el cero de la función g obtenido aplicando el método de Newton con tolerancia 1.e-6.*/
	printf("de Splines es\n%.10g\n\n", Newton(g, g1, 0.5, 1.e-6));
	printf("Reformulando la funcion L_{EA}(x) tal y como se indica en la memoria obtenemos ");
	/*Mostramos el cero de la función h obtenido aplicando el método de Newton con tolerancia 1.e-6.*/
	printf("\n%.10g\n\nAproximando las integrales haciendo uso de ", Newton(h, g1, 0.5, 1.e-6));
	printf("polinomios interpoladores de Splines y\n%.10g\n\nAproximando ", Newton(h1, g1, 0.5, 1.e-6));
	printf("las integrales mediante cuadratura de Gauss-Chebyschev\n\n");
	return 0;
}
コード例 #4
0
//int CollaborativeFiltering::MLEWeibullDistribution(vector<double> time_vec){
int CollaborativeFiltering::MLEWeibullDistribution(const string sql){
//	ifstream is;
//	is.open(filename.c_str());
//	if(!is){
//		cout << "cannnot open" << endl;
//		exit(1);
//	}
//
//	vector<double> time_vec;
//	vector<double>::iterator it;
//
//	while(!is.fail()){
//		double time;
//		is >> time;
//		time_vec.push_back(time);
//	}
//
//	it = time_vec.end();
//	time_vec.erase(--it);

//	Newton(time_vec, 1);
	Newton(sql, 1);

	return 0;

}
コード例 #5
0
ファイル: dc_roots.c プロジェクト: Iamthewood/PHCpack
void multiple_roots ( int n, dcmplx p[n], double eps, int maxit,
                      dcmplx r[n-1], double tol, int m[n-1] )
{
   int i,nit;
   dcmplx *dp[n-1];

   roots(n,p,eps,maxit,r);
   multiplicities(n-1,tol,r,m);
   derivatives(n,n-1,p,dp);
   /* write_derivatives(n,n-1,dp); */

   for(i=0; i<n-1; i++)
   {
      if (m[i] == 1)
         nit = Newton(n,p,dp[0],&r[i],eps,8);
      else
         nit = Newton(n-m[i]+1,dp[m[i]-2],dp[m[i]-1],&r[i],eps,8);

      /* printf("refined root %d : ", i);
         writeln_dcmplx(r[i]); */
   }
}
コード例 #6
0
//牛顿迭代函数
double Newton(double x)
{
	double a;
	a = (x+115.0/x)/2;
	if (fabs(a-x)<pow(10,-5))
	{
		return a;
	}
	else
	{
		return Newton(a);
	}
}
コード例 #7
0
ファイル: ChiSqNum.cpp プロジェクト: mxmlnkn/KPP
void ChiSquareNumeric::Calc(void) { //Calculate ChiSq-Minimum
    /* Minimize Chi-Square... I know, there is a Gauss-Newton Method which would
       be better, but this is a proof of concept, that it would work with fundamental
       functions. The optimization can be done later. */
    SetActive();
    *Parameter = Newton( (FuncVectorNParam) &NecessaryConditions, *Parameter);

    DegOfFreedom = NValues-Parameter->GetVectorDim();
    //CorrelCoeff = -a12/sqrt(a11*a22);                           //C(0,1)/(D*sqrt(C(0,0)/D)*sqrt(C(1,1)/D));
    //StDn = sqrt(a22/D);
	//StDm = sqrt(a11/D);
    //StDFit = sqrt(ChiSquare(x,y,yerr,N)/DegOfFreedom);
	return;
}
コード例 #8
0
ファイル: Newton.cpp プロジェクト: Neolus/C
void main()            //主函数
{ 

	double z;                             //定义变量
	printf("Please input the number of title \n ");            //输出题目选择
	scanf("%d",&b);                                        //题号赋值给b
	printf("Please input the order M \n");                 //输入求解阶数要求
	scanf("%d",&M);

	z=Newton(1,1e-7,1000,fm,df); //调用牛顿-拉夫森函数求解
	printf("z is %0.8f",z);
	getchar();
	getchar();

}
コード例 #9
0
ファイル: Ex5Q5.c プロジェクト: condiquendo/c-for-science
int main(void)
{
	double init, tol;
	int maxit;

	printf("F(x) = x*x - 2 = 0");

	printf("\n\nNewton-Raphson Method\n\nEnter initial guess: ");
	scanf("%lf", &init);
	printf("\nEnter maximum iterations: ");
	scanf("%d", &maxit);
	printf("\nEnter algorithm tolerance: ");
	scanf("%lf", &tol);
	
	printf("\nUsing %d iterations, the root of F(x) = 0 has been calculated as:\n\n", Newton(&init, F, dF, maxit, tol));
	printf("x = %.12f\n\nThis has a residue of %.10g\n", init, F(init));
	return 0;
}
コード例 #10
0
ファイル: main.cpp プロジェクト: efpies/MOptimizer
int main(int argc, const char * argv[])
{
    IFunction *targetFunction = selectFunction();   // Выбор целевой функции
    
    Point startPoint = inputPoint(*targetFunction);   // Ввод стартовой точки
    Point direction = inputDirection(*targetFunction, true); // Направление принимаем за единичный вектор
    
    double precision = inputPrecision();    // Ввод точности
    
    Point min = Newton().optimize(*targetFunction, startPoint, direction, precision);
    
    cout << "Minimum is:\t";
    min.print(precision);
    cout << endl << "F(min) is:\t";
    cout << targetFunction->value(min);
    
    return 0;
}
コード例 #11
0
int LinearElasticityEvaluator::Solve(){

  //ElasticityAssembler assembler(mesh,sf_factory,nodemap,bcdef);

  NewtonSolver Newton(*this);

  //NewtonSolver Newton(assembler);
  //Newton.Solve(1.0e-14);

  /*
  arma::wall_clock timer;
  std::cout << "In solve" << std::endl;

  timer.tic();
  // Solve the system
  computeSolutionBelos(KGLOB,RHS,DU,1,0,1000,1000,1.0e-14,false,"RILUK");
  std::cout << "Solve time: " << timer.toc() << std::endl;

  */ 

  

  return 1;
}