数模小白打卡第三天
主题活动
发布于 2025-08-18 16:43:37
查看 3过去314天
第一题使用反斜杠运算符和linsolve 函数,第二题使用TyOptimization库
A = Rational{Int}[1 2 3; -1 3 7; 9 0 3]
B = Rational{Int}[1, 4, 7]
x = A \ B
# 打印分数形式的解
println("Solution as exact fractions:")
println("x₁ = ", x[1])
println("x₂ = ", x[2])
println("x₃ = ", x[3])
# 导入TyMath库,使用 linsolve 函数
using TyMath
# 定义系数矩阵A和右侧向量B
A = [1 2 3; -1 3 7; 9 0 3]
B = [1; 4; 7]
# 求解线性方程组 Ax = B
x = linsolve(A, B)
using TyOptimization
x = optimvar("x", Lowerbnd=0) # 产品A的产量
y = optimvar("y", Lowerbnd=0) # 产品B的产量
#创建最大化问题
prob = optimproblem(ObjectiveSense="maximize")
#定义函数
prob.Objective = 40x + 30y
cons = 3x + 2y ≤ 1000
prob.Constraints = (;cons)
sol, = Solve(prob)
所属专栏:Julia语言
产品信息:Syslab科学计算环境