You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've run into a bit of a puzzle with symbolic_linear_solve, and I was hoping you could lend your expertise. I'm working with two sets of linear equations (included below), and while one solves without a hitch, the other is giving me some trouble. I've been trying to understand why using Symbolics.linear_expansion, and it seems that Test Case 1 is returning true, while Test Case 2 is returning false. I'm a bit stuck, so any advice or suggestions you might have would be fantastic!
Test Case 1: (Works)
eq = 8.85 - 8.85 * mp ~ (1+0.13) * er
Test Case 2: (Got "ERROR: LoadError: AssertionError: islinear" error)
eq = 8.85 ~ er / (1-mp) * (1+0.13)
Code
#!/usr/bin/env -S julia +releaseusing Symbolics
using Pkg
functionprintpackageversion(names::Vector{String})
deps = Pkg.dependencies()
for (uuid, dep) in deps
if dep.name in names
println("$(dep.name): v$(dep.version)")
endendendprintln("Julia: v$VERSION")
printpackageversion(["Symbolics"])
# er: exchange rate# mp: margin percent@variables er mp
# Test Case #1beginprintln("\n# Test Case #1")
@show eq =8.85-8.85* mp ~ (1+0.13) * er
@show Symbolics.linear_expansion(eq, mp)
@show n =symbolic_linear_solve(eq, er, simplify =true)
@showsubstitute(n, Dict(mp =>0.05))
@show n =symbolic_linear_solve(eq, mp, simplify =true)
@showsubstitute(n, Dict(er =>7.75))
end# Test Case #2beginprintln("\n# Test Case #2")
@show eq =8.85~ er / (1-mp) * (1+0.13)
@show Symbolics.linear_expansion(eq, mp)
@show n =symbolic_linear_solve(eq, er, simplify =true)
@showsubstitute(n, Dict(mp =>0.05))
@show n =symbolic_linear_solve(eq, mp, simplify =true)
@showsubstitute(n, Dict(er =>7.75))
end
Error
Julia: v1.11.2
Symbolics: v6.22.1
# Test Case #1
eq = (8.85 - 8.85mp ~ (1 + 0.13) * er) = 8.85 - 8.85mp ~ 1.13er
Symbolics.linear_expansion(eq, mp) = (8.85, -8.85 + 1.13er, true)
n = symbolic_linear_solve(eq, er, simplify = true) = 0.8849557522123894(8.85 - 8.85mp)
substitute(n, Dict(mp => 0.05)) = 7.4402654867256635
n = symbolic_linear_solve(eq, mp, simplify = true) = 0.11299435028248588(8.85 - 1.13er)
substitute(n, Dict(er => 7.75)) = 0.010451977401130071
# Test Case #2
eq = (8.85 ~ (er / (1 - mp)) * (1 + 0.13)) = 8.85 ~ (1.13er) / (1 - mp)
Symbolics.linear_expansion(eq, mp) = (0, 0, false)
n = symbolic_linear_solve(eq, er, simplify = true) = 7.831858407079646(1 - mp)
substitute(n, Dict(mp => 0.05)) = 7.4402654867256635
ERROR: LoadError: AssertionError: islinear
Stacktrace:
[1] symbolic_linear_solve(eq::Equation, var::Num; simplify::Bool, check::Bool)
@ Symbolics ~/.julia/packages/Symbolics/PxO3a/src/linear_algebra.jl:105
[2] macro expansion
@ show.jl:1232 [inlined]
[3] top-level scope
@ ~/Projects/Babel/Julia/TDSymbolics/TDSymbolics-TDislinear.jl:41
[4] include(fname::String)
@ Main ./sysimg.jl:38
[5] run(debug_session::VSCodeDebugger.DebugAdapter.DebugSession, error_handler::VSCodeDebugger.var"#3#4"{String})
@ VSCodeDebugger.DebugAdapter ~/.vscode-insiders/extensions/julialang.language-julia-1.127.2/scripts/packages/DebugAdapter/src/packagedef.jl:122
[6] startdebugger()
@ VSCodeDebugger ~/.vscode-insiders/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeDebugger/src/VSCodeDebugger.jl:45
[7] top-level scope
@ ~/.vscode-insiders/extensions/julialang.language-julia-1.127.2/scripts/debugger/run_debugger.jl:12
[8] include(mod::Module, _path::String)
@ Base ./Base.jl:557
[9] exec_options(opts::Base.JLOptions)
@ Base ./client.jl:323
[10] _start()
@ Base ./client.jl:531
in expression starting at ~/Projects/Babel/Julia/TDSymbolics/TDSymbolics-TDislinear.jl:34
* Terminal will be reused by tasks, press any key to close it.
The text was updated successfully, but these errors were encountered:
Case 2 isn't a linear expression. You can pre-process to multiply by 1-mp to make it one, but currently this solver function is not capable of doing that.
Issue
I've run into a bit of a puzzle with symbolic_linear_solve, and I was hoping you could lend your expertise. I'm working with two sets of linear equations (included below), and while one solves without a hitch, the other is giving me some trouble. I've been trying to understand why using Symbolics.linear_expansion, and it seems that Test Case 1 is returning true, while Test Case 2 is returning false. I'm a bit stuck, so any advice or suggestions you might have would be fantastic!
Test Case 1: (Works)
eq = 8.85 - 8.85 * mp ~ (1+0.13) * er
Test Case 2: (Got "ERROR: LoadError: AssertionError: islinear" error)
eq = 8.85 ~ er / (1-mp) * (1+0.13)
Code
Error
The text was updated successfully, but these errors were encountered: