X(浓度) Y反应值 5000.00 2.14 2500.00 1.48 1250.00 0.97 625.00 0.55 312.00 0.34 5组数据 X为浓度 Y为反应值, 方程: y = (A - D) / [1 + (x/C)^B] + D A表示最大反应值,D表示基础响应值,B表示斜率因子,C表示EC50浓度值 计算出A,B,C,D是如下的数值 A = 4.13315 B = -0.93745 C = 4727.53029 D = 0.03518 写一个C++或C语言的代码
时间: 2024-02-10 09:05:49 浏览: 52
Microsoft.VCLibs.x64.14.00.Desktop.appx
下面是使用C++语言实现的计算A、B、C、D的代码:
```c++
#include <iostream>
#include <cmath>
using namespace std;
double x[] = { 5000.00, 2500.00, 1250.00, 625.00, 312.00 };
double y[] = { 2.14, 1.48, 0.97, 0.55, 0.34 };
int n = 5;
double logistic(double x, double A, double B, double C, double D) {
return (A - D) / (1 + pow(x / C, B)) + D;
}
void four_param_fit(double *x, double *y, int n, double &A, double &B, double &C, double &D) {
double ym = y[0];
double xm = x[0];
for (int i = 1; i < n; i++) {
if (y[i] > ym) {
ym = y[i];
xm = x[i];
}
}
A = ym;
B = -1;
C = xm;
D = y[0];
double eps = 1e-8;
double err = 1;
while (err > eps) {
double A1 = A;
double B1 = B;
double C1 = C;
double D1 = D;
for (int i = 0; i < n; i++) {
double f = logistic(x[i], A, B, C, D);
double dfdA = 1 / (1 + pow(x[i] / C, B));
double dfdB = (A - D) * pow(x[i] / C, B) * log(x[i] / C) / pow(1 + pow(x[i] / C, B), 2);
double dfdC = (A - D) * B * pow(x[i] / C, B - 1) * pow(C, -2) / pow(1 + pow(x[i] / C, B), 2);
double dfdD = 1 / (1 + pow(x[i] / C, B));
A1 += (y[i] - f) * dfdA;
B1 += (y[i] - f) * dfdB;
C1 += (y[i] - f) * dfdC;
D1 += (y[i] - f) * dfdD;
}
err = sqrt(pow(A1 - A, 2) + pow(B1 - B, 2) + pow(C1 - C, 2) + pow(D1 - D, 2));
A = A1;
B = B1;
C = C1;
D = D1;
}
}
int main() {
double A, B, C, D;
four_param_fit(x, y, n, A, B, C, D);
cout << "A = " << A << ", B = " << B << ", C = " << C << ", D = " << D << endl;
return 0;
}
```
在该示例代码中,输入数据为5个点的x和y值,输出为计算得到的A、B、C、D的值。该代码使用了最小二乘法进行四参数Logistic曲线拟合的计算,其中`four_param_fit`函数用于计算四个参数的值,`logistic`函数用于计算Logistic函数的值。
阅读全文