# Problem simulating Matlab ODE15s in Julia

Here is the code I have,

``````using Pkg
using PyCall

using CSV; using DataFrames; using Dierckx;using DifferentialEquations;using  LSODA;using MATLABDiffEq; using ParameterizedFunctions;using IfElse;

p = [
1.35e-2  #k1
6.33e-1  #k2
5.00e-5  #k3
1.00e-3  #k4
3.80e-3  #k5
5.82e-1  #k6
2.20e-2  #k7
4.71     #k8
1.08e-2  #k9
#2.6     REMOVED
1.35     #sigma /index 10
0.63     #Km /index 11
5.0      #Gb /index 12
8.58     #Ib /index 13
]

input = [
75000, # D
70, # Mb
0 # t_meal_start
]

c = [0.00551,
17/70,
0.043,
1,
31,
3,
13/70,
9,
30,
0.1,
0.043*(p+p)/p-p*1*p,
p*p/(1*31*p)*30
]
function differentialequations_1(du,u,p,t)
Mg,Gpl,Ipl,Int=u

mg = IfElse.ifelse(t> input, p.*p.^p.*(t-input).^(p-1) .* exp(-(p.*(t-input)).^p) .* input,0)

mgpl = p .* Mg
du = mg - mgpl

gli    = c - p .* (Gpl-p)-p .* c .* (Ipl-p)

ggu    = p .* (c/(c*input)) .* Mg;
gnoni  = c .* (Gpl./(p+Gpl));
gi     = p .* c .* Ipl .* (Gpl./(p+Gpl))
gre= IfElse.ifelse(Gpl > c, c ./ (c*input) .* (Gpl - c), 0 )
du = gli + ggu - gnoni - gi - gre

t_lowerbound= t- c;

if (time > c) && (length(t_saved)>1) && (length(t_saved) == length(Gpl_saved))
spl=Spline1D(t_saved,Gpl_saved)
Gpl_lowerbound= spl(t_lowerbound);
else
Gpl_lowerbound = Gpl_saved;
end

du = (Gpl-p) - (Gpl_lowerbound-p);
ipnc = (c.^-1) .* (p.*(Gpl-p) +(p/c).*Int + (p/c) .*p* c + (p.*c) .* du)

iliv    = c.*Ipl;
iif     = p.*(Ipl-p)

du = ipnc - iliv - iif

end

function compute(u0, local_G_saved,local_I_saved)

global time=0
global t_saved=

convert(Any, local_G_saved)
convert(Any, local_I_saved)
while   time < 120
tspan = (time, time+1)

prob = ODEProblem(differentialequations_1,u0,tspan,p)
sol=solve(prob, MATLABDiffEq.ode15s())
time=  time+1
convert(Any, sol)
push!(t_saved, time)
push!(local_G_saved, last(sol[2,:]))
push!(local_I_saved,last(sol[3,:]))
u0=last(sol)

end

return local_G_saved, local_I_saved, u0
end

global Gpl_saved= 5.0
global Ipl_saved=11.5
u0=[0.0,5.0,11.5,0.0]
p=0.00933
p=0.01
p=0.3
p=3.3
simulated_G_saved, simulated_I_saved, u= compute(u0, Gpl_saved,Ipl_saved);
``````

which when run provides the error

Unable to resolve the name mxsol.stats.

Now, I have tried reproducing the error is a smaller version but unfortunately I could not. With every attempt there were some other issues popping up. In some cases, the 4th u variable entirely disappeared in the 2nd iteration. Please run the code and see if you can reproduce the error and see where the flaw is.
I tried to follow the julia recommended coding practices, but please feel free to provide additional pointers if necessary.

Thanks in advance Better:

``````using CSV, DataFrames, Dierckx, DifferentialEquations, LSODA, MATLABDiffEq, ParameterizedFunctions, IfElse
``````

OK, I still have to look at the main issue…

Just realized that you want to use Matlab to solve a differential equation. I do not have a license, so I cannot help you, sorry… Why do you want to use Matlab in the first place?

I noticed a difference between the simulated results from Matlab and Julia. So by using the MatlabDiffEq package I want to ensure my Julia implementation is actually correct.

What version of MATLAB is that?

On the phone now, but i think `pkg> add MATLABDiffEq#ChrisRackauckas-patch-1` would add that specifik version.