@@ -294,6 +294,75 @@ function fractional_to_ordinary(eqs, variables, alphas, epsilon, T; initials = 0
294294    return  mtkcompile (sys)
295295end 
296296
297+ function  linear_fractional_to_ordinary (degrees, coeffs, rhs, epsilon, T; initials =  0 )
298+     @independent_variables  t
299+     @variables  x_0 (t)
300+     D =  Differential (t)
301+     i =  0 
302+     all_eqs =  Equation[]
303+     all_def =  Pair{Num, Int64}[]
304+ 
305+     function  fto_helper (sub_eq, α)
306+         δ =  (gamma (α+ 1 ) *  epsilon)^ (1 / α)
307+         a =  pi / 2 * (1 - (1 - α)/ ((2 - α) *  log (epsilon^- 1 )))
308+         h =  2 * pi * a /  log (1  +  (2 / epsilon *  (cos (a))^ (α -  1 )))
309+ 
310+         x_sub =  (gamma (2 - α) *  epsilon)^ (1 / (1 - α))
311+         x_sup =  - log (gamma (1 - α) *  epsilon)
312+         M =  floor (Int, log (x_sub /  T) /  h)
313+         N =  ceil (Int, log (x_sup /  δ) /  h)
314+ 
315+         function  c_i (index)
316+             h *  sin (pi  *  α) /  pi  *  exp ((1 - α)* h* index)
317+         end 
318+ 
319+         function  γ_i (index)
320+             exp (h *  index)
321+         end 
322+ 
323+         new_eqs =  Equation[]
324+         def =  Pair{Num, Int64}[]
325+         sum =  0 
326+         for  index in  range (M, N- 1 ; step= 1 )
327+             new_z =  Symbol (:z , :_ , i)
328+             i +=  1 
329+             new_z =  ModelingToolkit. unwrap (only (@variables  $ new_z (t)))
330+             new_eq =  D (new_z) ~  sub_eq -  γ_i (index)* new_z
331+             push! (new_eqs, new_eq)
332+             push! (def, new_z=> 0 )
333+             sum +=  c_i (index)* new_z
334+         end 
335+         return  (new_eqs, def, sum)
336+     end 
337+ 
338+     previous =  x_0
339+     for  i in  range (1 , ceil (Int, degrees[1 ]); step= 1 )
340+         new_x =  Symbol (:x , :_ , i)
341+         new_x =  ModelingToolkit. unwrap (only (@variables  $ new_x (t)))
342+         push! (all_eqs, D (previous) ~  new_x)
343+         push! (all_def, previous =>  initials[i])
344+         previous =  new_x
345+     end 
346+ 
347+     new_rhs =  - rhs
348+     for  (degree, coeff) in  zip (degrees, coeffs)
349+         rounded =  ceil (Int, degree)
350+         new_x =  Symbol (:x , :_ , rounded)
351+         new_x =  ModelingToolkit. unwrap (only (@variables  $ new_x (t)))
352+         if  isinteger (degree)
353+             new_rhs +=  coeff *  new_x
354+         else 
355+             (new_eqs, def, sum) =  fto_helper (new_x, rounded -  degree)
356+             append! (all_eqs, new_eqs)
357+             append! (all_def, def)
358+             new_rhs +=  coeff *  sum
359+         end 
360+     end 
361+     push! (all_eqs, 0  ~  new_rhs)
362+     @named  sys =  System (all_eqs, t; defaults= all_def)
363+     return  mtkcompile (sys)
364+ end 
365+ 
297366""" 
298367    change_independent_variable( 
299368        sys::System, iv, eqs = []; 
0 commit comments