python and weierstrass function
python and weierstrass function
基于此函数。我正在尝试创建两个空数组(一个用于 x,另一个用于 y),稍后我将用它们在 python 中绘制。但在此之前,这就是我迄今为止所拥有的......
import math
x1=-2.0
x2=2.0
arr1 = []
arr2 = []
i=0
n=10
delta=(x2-x1)/n
for i in range (0,n+1):
x=x1+delta*i
arr1.append(x)
print arr1
# I have not called the w function yet
上面的代码现在创建了一个包含 10 个数字的列表,以保持简单。然后它将数组的元素发送到下面的函数,并计算具有某些数字(无限循环)的方程。
#This function will create the array list for y
import math
def w(x, limit):# the limit here to compare when the number is really small
suma = 0.0
sumb = 0.0
m=1
x=0
suma=suma+((1/(math.pow(2,m))*(math.sin(math.pow(2,m)*x)))
sumb=suma+((1/(math.pow(2,m+1))*(math.sin(math.pow(2,m+1)*x))) # I'm having a
#syntax error
#here
x+=0
if (abs (suma-sumb)<limit):
break:
else m+=1:
if (m<20):
break:
我将不胜感激任何关于我的语法错误或任何建议的帮助。我只是希望我足够清楚。提前致谢
语法错误实际上在上一行,其中括号不平衡。您需要在该行的末尾加一个额外的)
(顺便说一句,在您指出的那个也给出了错误)。
还有一些其他问题
-
suma
设置为零,所以suma = suma + ...
与suma = ...
相同,但我猜你仍然需要在此行之前添加while
循环。 - 在指示的行上,您有
sumb = suma +
,这可能是复制/粘贴错误。 - 从
x+=0
开始的代码块仅缩进 3 个空格,而不是 4 个空格。在你的实际代码中可能不是这种情况,但如果是这样,Python 也会抱怨这一点。 -
else m+=1:
应该是else: m+=1
(冒号紧跟在else
之后,而不是在行尾。 -
break:
应该只是break
(没有冒号)。
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- Confusion: decltype vs std::function
- 为什么 std::function 可以作为 std::not2 的参数?
- 'max'匹配'std::function<const int &(const int &, const int &)>'无过载
- 传递给std::function template的template参数究竟代表什么
- 将带有unique_ptr的可变 lambda 传递给 const&std::function
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- "no matching function for call to 'Vector::Vector'"错误
- 如何在向量中删除 std::function<void()>?
- 不断"Attempting to reference a deleted function"
- 将函数包装器转换为 std::function
- 类型擦除的std::function与虚拟函数调用的开销
- C++ std::function 对于类 exept 的所有实例都是空的(只有 Visual2019 编译器问题)
- 如果模板没有可变参数,则 Lambda 被推导出为 std::function
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 模板规范获取'Ambiguous call to overloaded function'
- 将 lambda 表达式传递给 std::function in C++
- python and weierstrass function