xbroydn.c

来自「< C语言数值算法程序大全>>配套程序」· C语言 代码 · 共 36 行

C
36
字号
/* Driver for routine broydn */

#include <stdio.h>
#include <math.h>
#define NRANSI
#include "nr.h"
#include "nrutil.h"

void funcv(int n,float x[],float f[])
{
	f[1]=SQR(x[1])+SQR(x[2])-2.0;
	f[2]=exp(x[1]-1.0)+x[2]*SQR(x[2])-2.0;
}

#define N 2

int main(void)
{
	int i,check;
	float *x,*f;

	x=vector(1,N);
	f=vector(1,N);
	x[1]=2.0;
	x[2]=0.5;
	broydn(x,N,&check,funcv);
	funcv(N,x,f);
	if (check) printf("Convergence problems.\n");
	printf("%7s %3s %12s\n","Index","x","f");
	for (i=1;i<=N;i++) printf("%5d %12.6f %12.6f\n",i,x[i],f[i]);
	free_vector(f,1,N);
	free_vector(x,1,N);
	return 0;
}
#undef NRANSI

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?