在 for 循环中初始化的变量是否每次迭代都会重置
Does a variable initialized in a for loop get reset every iteration?
for (i=0;i<=n;i++) {
fsten[i]=fx(xsten[i]); //fsten[0] = fx(xsten[0]); fsten[1] = fx(xsten[1]); ...; etc. initializing the fsten array up to n times.
} //end of initial for loop
y=0.0;
for (i=0;i<=n;i++) {
L=1.0; //the lagrange basis polynomial
for (j=0;j<=n;j++) {
if (i!=j) {
L=L*(x-xsten[j])/(xsten[i]-xsten[j]);
} //end of if statement
} //end of second for loop
y=y+fsten[i]*L;
}//end of first for loop
我正在做拉格朗日多项式迭代。我们正在查看 y=0.0 之后的第二个 for 循环。在 for 循环的末尾,j=0
,我们有 y = y+fsten[i]*L
L显然不再1
。但是当它进入i=1
这是否意味着 L=1.0 再次为真?
是的,这又是正确的,因为您再次运行循环的主体,并且L = 1.0
确实将变量L
设置为 1.0
。
相关文章:
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- std::vector::迭代器是否可以合法地作为指针
- 是否应避免从非常量迭代器转换为常量迭代器?
- 钳制迭代器是否有效
- 如何将 UTF-8 文本从文件转换为某个可以迭代的容器,并检查每个符号是否为C++字母数字?
- 测试迭代器是否位于列表中的最后一个
- 迭代器在递增和递减时是否保证会变异?
- 是否可以(重新)分配来自不同容器的迭代器?
- 调用 erase() 函数是否也会在擦除元素之前更改迭代器值?
- 在迭代期间添加到 std::unordered_set(或 unordered_map)中的元素是否会在迭代期间访问?
- 使用 Rcpp 加速替换迭代算法中的列表和向量元素是否合法?
- 循环中本地对象的析构函数是否保证在下一次迭代之前被调用?
- 迭代器是否分配内存(如指针)?
- 在擦除或修改作为不同索引键的值时,boost::multi_index 迭代器是否无效?
- 使用自己的迭代器分配容器是否安全?
- 对于C字符串,是否有一个标准的C++迭代器
- 我当前实现的双向链表类是否需要重构迭代器 end() 功能?
- 在C++中,是否可以在单个循环中顺序迭代多个迭代器
- 是否可以使用OpenMP并行化一个列表,该列表可以在每次迭代中添加新元素
- 迭代是否遍历整个列表