How to learn how to solve equations in Julia 1.0? Because I am a beginner, I am only interested in relatively simple problems such as basic optimization. I found a book that seemed relevant but it predates Julia 1.0: Julia Programming for Operations Research: A Primer on Computing.
For example, I have the equation:
1/((1+p)^30)*10,000=100
I need to solve p. How to do it in Julia 1.0?
The example was recently discussed on Statalist. In addition to a partial programming solution in Stata, one user suggested to simply type the input online into Wolfram Alpha which works as a simple non-Julia solution. I considered the Julia packages JuMP.jl, Optim.jl and IterativeSolvers.jl but none seem ready for 1.0. My only attempt in Julia was to simply type the input but then I get this error:
julia> 1/((1+p)^30)*10,000=100
ERROR: syntax: "(1 / ((1 + p) ^ 30))" is not a valid function argument name
I looked at the Julia manual for functions but could not find a relevant usage example.
But, you need to have some basic knowledge of programming and understand the syntax of Julia before you can take any benefit from using Julia. The Julia Manual is mainly about the language itself. For a concrete application like solving equations, one typically loads a package for that purpose.
As Norman says, you should try to familiarise yourself with basic programming notions to get a feel for how you can translate your problems into code.
The Statalist post you linked sort of explains how you can achieve what youāre trying to do, so porting it to Julia shouldnāt be too hard. Youād have to take a two-step approach:
Translate your mathematical expression into a Julia function. This could be e.g.:
function to_solve(p)
return abs(1 / ( (1+p)^30 ) * 10_000 - 100)
end
The basic idea here being that you transform it into a function for which the minimum is zero (namely for the p that sets the left hand side of the original equation to 100.
Then you need to find a solver to plug this function into, which essentially applies an algorithm to search over different values of p to find the one that minimizes the function - your original post has some options for this, with Norman giving you another one. You need to check the solverās documentation to understand how to call the function that finds your solution.
FWIW I see some deprecation warnings on Optim.jl currently on 0.7 but it seems to work.
How is that possible as it now requires 1.0? I thought you only get the warnings in 0.7 (when applies) and errors in 1.0. Did you maybe not update to the latest version?
EDIT: I see it now, using Julia 0.7 will keep you on older 0.16.0, while 1.0 will enable you to upgrade to latest 0.17.1.
Iām guessing Julia 1.0 is now recommended; and increasingly for other packages too (I thought I should recommend 0.7 to users, over 1.0, but that seems outdated, if it ever was true, for non-package developers).
That might well be the case - I havenāt had to solve an optimisation problem in a while so am not following along closely with the relevant packages. Iām on Optim 0.16.0.
You can also use the IntervalRootFinding package, which guarantees (in the best cases) to find all roots and guarantee that they are unique within the respective found intervals:
julia> using IntervalArithmetic, IntervalRootFinding
WARNING: using IntervalRootFinding.Bisection in module Main conflicts with an existing identifier.
julia> roots(f, -ā..ā)
2-element Array{Root{Interval{Float64}},1}:
Root([0.165914, 0.165915], :unique)
Root([-2.16592, -2.16591], :unique)