UndefVarError: Model not defined - julia

How should I fix the following error?
Pkg.add("JuMP")
Pkg.add("Clp")
m = Model()
and I get the following error:
LoadError: UndefVarError: Model not defined
while loading In[4], in expression starting on line 1

You should use using JuMP before calling m=Model()

Related

could not find function "as.party.Weka_tree"

I'm struggling with an error message that I don't understand. I'm doing some decision trees and everything goes fine, until I try to plot it
plot(as.party.Weka_tree(CostSensitive_Tree))
which gives this error:
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'plot': could not find function "as.party.Weka_tree"
I checked multiple times with help.search("as.party.Weka_tree")and the package (
partykit) is installed, what could be the cause of this error?
Thanks!
First, you need to make sure that the package is loaded, i.e., library("partykit"). Second, you should not call the S3 method directly but just say as.party(CostSensitive_Tree). Internally the as.party() generic function then dispatches to the as.party.Weka_tree() method but the latter should not be called directly.

Julia 1.1 x=x+1 in for loop returned error

I'm using Julia 1.1 and I tried to use for loop do the following simple things:
i_index=1;
for index in (1:100)
i_index=i_index+1;
end
However, I got an error saying:
ERROR: UndefVarError: i_index not defined
I have tried several times and variations, but they all failed to work. Is this a bug? or why Julia can't do this simple iterative addition?
In the REPL:
i_index=1;
for index in (1:100)
global i_index;
i_index=i_index+1;
end
This is because of variable scope, see in Julia documentation. Note that the examples there pertain to the REPL.

Pkg not defined

I tried following the official Julia docs on plotting, where the following code is proposed for plotting:
Pkg.add("PyPlot")
using PyPlot
x = range(0,stop=2*pi,length=1000); y = sin.(3*x + 4*cos.(2*x))
plot(x, y, color="red", linewidth=2.0, linestyle="--")
Julia v1.0.2 exits with the error
ERROR: LoadError: UndefVarError: Pkg not defined
My question is how to actually run the above code?
The problem is that the Pkg module is not loaded, because this seems to be deprecated. To fix this the following line has to be added before the first line
using Pkg
The code then works for me not from the command line interface, but within an interactive julia session and produces the following image:

failed to execute first example of Differential Algebraic Equations

I am using JuliaPro v0.6.0.1 and the JunoIDE
I tried to apply the DifferentialEquations.jl. In order to run a first example I added the package DifferentialEquations followed by the using statement. In a next step I copied the first example:
f(t,u) = 1.01*u
u0=1/2
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8)
using Plots
plot(sol,linewidth=5,title="Solution to the linear ODE with a thick line",
xaxis="Time (t)",yaxis="u(t) (in μm)",label="My Thick Line!") # legend=false
plot!(sol.t, t->0.5*exp(1.01t),lw=3,ls=:dash,label="True Solution!")
Instead of getting the expected graphic I've got the message:
UndefVarError: ODEProblem not defined
Furthermore I've got the warnings right after the: using DifferentialEquations statement
WARNING: The call to compilecache failed to create a usable precompiled cache file for module StochasticDiffEq. Got:
WARNING: Module Iterators uuid did not match cache file.
> LoadError: Declaring __precompile__(true) is only allowed in module files being imported.
which I do not understand. Nevertheless the last warning deals with StochasticDiffEq whereas I'm applying an Ordinary Differential Equation problem.
Any help is appropiated
JuliaPro is incompatible with some packages including DifferentialEquations. I would avoid using JuliaPro and instead use a standard installation until JuliaPro is updated.

unable to find C_kmns object when passed to .Fortran()

I'm trying to modify the stats::kmeans function to return the number of iterations (see here). When I copy the source to my own file, modify the function and run it, I get an error about object C_kmns missing when trying to execute the do_one function. This object is passed to a .Fortran call and is not being created anywhere in the kmeans function. Where does this object come from?
The error I'm getting is
Error in do_one(nmeth) : object 'C_kmns' not found
Here's a code snippet of the "offending" call.
do_one <- function(nmeth) {
Z <-
switch(nmeth,
{ # 1
Z <- .Fortran(C_kmns, as.double(x), as.integer(m),
as.integer(ncol(x)),
...
C_kmns is a non-exported object in the stats namespace. You can solve the issue by telling R where to find it with stats:::C_kmns. in your example:
Z <- .Fortran(stats:::C_kmns, as.double(x), as.integer(m),
as.integer(ncol(x)),
...
In general, when you get an object not found error, you can go looking for it with getAnywhere("C_kmns")

Resources