>>> import math
#defining first function
>>> def f(a):
return a-math.sin(a)-math.pi/2
#defining second fuction
>>> def df(a):
return 1-math.cos(a)
#defining third function which uses above functions
>>> def alpha(a):
return a-f(a)/df(a)
如何编写一个代码,其中alpha(a)取a=2的起始值,alpha(2)的解将成为下一次的输入。例如:假设alpha(2)是2.39,因此下一个值是alpha(2.39),并且继续{50次迭代}。谁能帮我一点忙吗。提前谢谢。你知道吗
你可以把它具体化。你知道吗
然后创建一个
inout
对象,每次调用它的alpha
方法时,它都会给出序列中的下一个值。你知道吗您可以让程序使用
for
循环进行迭代,并使用变量存储中间结果:print(temp)
将打印中间结果。它不是必需的。它只演示如何在整个过程中更新temp
变量。你知道吗相关问题 更多 >
编程相关推荐