julia - Julia UndefVarError 关于元编程
问题描述
我正在尝试为方程做一个求解器。当我运行代码时,X
变量似乎是未定义的,但它打印出来很完美。我错过了什么?我应该给程序一些数字,而不是宏的操作,它应该创建应用操作的外积矩阵。
function msu()
print("Insert how many values: ")
quantity = parse(Int64, readline())
values = []
for i in 1:quantity
println("x$i")
num1 = parse(Float64, readline())
push!(values, num1)
end
println(values)
print("How many operations? ")
quantity = parse(Int64, readline())
ops = []
for i in 1:quantity
push!(ops, Meta.parse(readline()))
end
mat = zeros((quantity, quantity))
for i in 1:length(mat)
sum = 0
for j in 1:length(values)
# here begins problems, the following prints are for debugging purpose
print(length(values))
func = Meta.parse("$(ops[convert(Int64, ceil(j / quantity))]) * $(ops[convert(Int64, j % quantity)])")
print(func)
x = values[j]
println(x)
sum += eval(func)
end
mat[i] = sum
end
println(mat)
end
msu()
原始代码是西班牙语,如果您发现任何拼写错误,可能是因为我跳过了翻译。
解决方案
推荐阅读
- php - Laravel + NGINX 给 403 禁止
- c# - Mscorlib 找不到抛出 FileLoadException 的依赖项
- angular - 隔离内部形式
- sql-server - 如何使用 SQL Server 中的 Regiseterd Server 将多个表中的数据插入到单个表中
- apache - Apache HTTPD 中的 Lua - 未定义某些函数
- c# - Azure Web App - 如何使用 fluent API 更新 MinTlsVersion
- ruby - 我想在 Ruby 编程中使用 Repl.it 并读取一个 UNICODE 文本文件,但它不起作用。它发出错误消息
- c++ - 尝试使用 CLion 使用 .C 和 .CPP 文件构建项目时出现未定义的引用错误
- html - 将引导卡头中的多个组件在左侧和右侧连续对齐的最佳方法
- bash - Zsh 别名不起作用,但在终端中粘贴时命令确实有效