@@ -184,15 +184,14 @@ function change_of_variables(
184184    return  new_sys
185185end 
186186
187- function  FDE_to_ODE (eqs, alphas, epsilon, T; initials= 0 )
187+ function  FDE_to_ODE (eqs, variables,  alphas, epsilon, T; initials= 0 )
188188    @independent_variables  t
189-     @variables  x (t)
190189    D =  Differential (t)
191190    i =  0 
192191    all_eqs =  Equation[]
193192    all_def =  Pair{Num, Int64}[]
194193
195-     function  FDE_helper (sub_eq, α; initial= 0 )
194+     function  FDE_helper (sub_eq, sub_var,  α; initial= 0 )
196195        alpha_0 =  α
197196        if  (α >  1 )
198197            coeff =  1 / (α -  1 )
@@ -222,10 +221,10 @@ function FDE_to_ODE(eqs, alphas, epsilon, T; initials=0)
222221        end 
223222
224223        new_eqs =  Equation[]
225-         rhs =  initial
226224        def =  Pair{Num, Int64}[]
227225
228-         if  (α <  1 )
226+         if  (α <  1 )  
227+             rhs =  initial
229228            for  index in  range (M, N- 1 ; step= 1 )
230229                new_z =  Symbol (:z , :_ , i)
231230                i +=  1 
@@ -236,27 +235,32 @@ function FDE_to_ODE(eqs, alphas, epsilon, T; initials=0)
236235                rhs +=  c_i (index)* new_z
237236            end 
238237        else 
238+             rhs =  0 
239+             for  (index, value) in  enumerate (initial)
240+                 rhs +=  value *  t^ (index -  1 ) /  gamma (index)
241+             end 
239242            for  index in  range (M, N- 1 ; step= 1 )
240243                new_z =  Symbol (:z , :_ , i)
241244                i +=  1 
242245                γ =  γ_i (index)
246+                 base =  sub_eq
243247                for  k in  range (1 , m; step= 1 )
244248                    new_z =  Symbol (:z , :_ , index- M, :_ , k)
245249                    new_z =  ModelingToolkit. unwrap (only (@variables  $ new_z (t)))
246-                     new_eq =  D (new_z) ~  sub_eq  -  γ* new_z
247-                     sub_eq  =  k *  new_z
250+                     new_eq =  D (new_z) ~  base  -  γ* new_z
251+                     base  =  k *  new_z
248252                    push! (new_eqs, new_eq)
249253                    push! (def, new_z=> 0 )
250254                end 
251255                rhs +=  coeff* c_i (index)* new_z
252256            end 
253257        end 
254-         push! (new_eqs, x  ~  rhs)
258+         push! (new_eqs, sub_var  ~  rhs)
255259        return  (new_eqs, def)
256260    end 
257261
258-     for  (eq, alpha) in  zip (eqs, alphas)
259-         (new_eqs, def) =  FDE_helper (eq, alpha)
262+     for  (eq, cur_var,  alpha, init ) in  zip (eqs, variables,  alphas, initials )
263+         (new_eqs, def) =  FDE_helper (eq, cur_var,  alpha; initial = init )
260264        append! (all_eqs, new_eqs)
261265        append! (all_def, def)
262266    end 
0 commit comments