C语言一元二次函数系数计算

这里写自定义目录标题

C一元二次方程求解(二维数组)

// An highlighted block
	#include <stdio.h>

static float mean(float *values, int length);
static float variance(float *values, float mean, int length);
static float covariance(float *x, float mean_x, float *y, float mean_y, int length);
void coefficients(float *dataSDC, float *dataLogger, float *coef, int length);
static float mathfuc(float *number,float *voltage,float *paramter);
static float mathfucArray(float *number,float *voltage,float *paramter);
static void setnumber(int *numbercount , float *number);


float paramter[12][2] = {{0,0}};
float number[12][2] = {{1,20},{21,40},{41,60},{61,80},{1,20},{21,40},{41,60},{61,80},{81,100},{101,120},{121,140},{141,160}};
float voltage[12][2] = {{0,20},{21,625},{626,1250},{1251,2500},{0,19},{20,39},{40,78},{79,156},{157,312},{313,625},{626,1250},{1251,2500}};
int numbercount = 20;


int main(void) {
   
	setnumber(&numbercount , number[0]);
	mathfucArray(number[0],voltage[0],paramter[0]);
    return 0;
}
static float mathfucArray(float *number,float *voltage,float *paramter)
{
	for (int i = 0; i<12; i++) {
		//  for (int j= 0; j<2; j++) {
		mathfuc((number+2*i),(voltage+2*i),(paramter+2*i));
		//  }
		printf("%f,%f!\n",*(paramter+2*i),*(paramter+2*i+1));	
	}

}
static void setnumber(int *numbercount , float *number)
{
		for (int i = 0; i<12; i++) {
			if (i<4) {
			for (int j = 0; j<2; j++) {
				if (j == 0) {
				*(number+2*i+j) = 1 + *numbercount * i;
				}else {
				*(number+2*i+j) = *numbercount * (i + 1);
				}	
			}
			printf("%f,%f!\n",*(number+2*i),*(number+2*i+1));
			}else {
			for (int j = 0; j<2; j++) {
				if (j == 0) {
				*(number+2*i+j) = 1 + *numbercount * (i-4);
				}else {
				*(number+2*i+j) = *numbercount * (i - 3);
				}	
			}
			printf("%f,%f!\n",*(number+2*i),*(number+2*i+1));
			}
			
		}
}
static float mathfuc(float *number,float *voltage,float *paramter)
{
	float a = 0;
	float b = 0;
	// *voltage = *number * a + b;
	// *(voltage+1) = *(number+1) * a + b;
	a = *(voltage+1) - *voltage;
	a /= *(number+1) - *number;
	b = *voltage - a * (*number);
	*paramter = a;
	*(paramter+1) = b;

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值