如何将值存储到结果数组中? [英] How do I store value into a result array?
本文介绍了如何将值存储到结果数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有4个阵列。 a = 6个索引,b = 20个索引,x& t = 10001个索引。我必须计算10001个值,然后求它,然后将它们全部加起来。我必须使用(a,b)的唯一组合(x,t)的每个值来操作公式。
I have 4 arrays. a=6 indexes, b=20 indexes, x&t=10001 indexes. I have to calculate 10001 values and then sum it and then sum it all up. I have to operate the formula using unique combinations of (a,b) against every value of (x,t).
long double temps[10001];
long double result = 0;
long double resids[120];
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 20; j++)
{
for (int k = 0; k < 10001; k++)
{
temps[i] = pow((x[k] - (a[i] + (0.955 - a[i])*(exp(-(b[j]) * t[k])))), 2);
result += temps[i];
}
for (int l = 0; l < 120; l++)
{
resids[l] = result;
}
}
}
推荐答案
我发现此代码存在多个问题。要专门回答你关于结果数组的问题...
I see multiple problems with this code. To specifically answer your question about the result array ...
long double temps[10001];
long double result = 0;
long double resids[120];
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 20; j++)
{
result = 0; // unsure
for (int k = 0; k < 10001; k++)
{
temps[i] = pow((x[k] - (a[i] + (0.955 - a[i])*(exp(-(b[j]) * t[k])))), 2);
result += temps[i];
}
resids[i * 20 + j] = result; // <-- 120 results go here.
}
}
我无法确定在每次i传递开始时是否应将结果重置为零或每个j通过。
I can't tell whether "result" should be reset to zero at the start of each "i" pass or each "j" pass.
这篇关于如何将值存储到结果数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文