Unable to simulate a problem in simulink that runs effortlessly in Python.
Show older comments
Hi! I wish to simulate a problem in simulink that I simulated in Python last year. This problem is throwing a lot of problems in simulink from singularity issues to algebraic loop. The python code is as follows-
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
from numpy import tanh,sin,cos
t=np.linspace(0,100,10000)
y0=[0.3,-.4,0.1,0.3,0.5]
b,a1,a2,gamma,gamma1,gamma2,c,eta,k=2,1,3,7,5,6,3,1.5,15
def f(Y,t):
thetadot,psi,psidot,h1,h2=Y[0],Y[1],Y[2],Y[3],Y[4]
psiddot=a1*thetadot
e=psi-np.sin(t)
edot=psidot-np.cos(t)
eddot=psiddot+sin(t)
s=eddot+c**2*e+2*c*edot
u=h2*psidot+h1*(-cos(t))-h1*c**2*edot-2*h1*c*eddot-eta*tanh(s)-k*s
thetaddot=-a2*psidot+b*u
#hdot=gamma*(c*edot*s+np.sin(t)*s+.1*tanh(s)+2*s)
h1dot=-gamma1*(-cos(t)-c**2*edot-2*c*eddot)*s
h2dot=-gamma2*s*psidot
return[thetaddot,psidot,psiddot,h1dot,h2dot]
sol=odeint(f,y0,t)
thetadot=sol[:,0]
psi=sol[:,1]
psidot=sol[:,2]
h1=sol[:,3]
h2=sol[:,4]
plt.figure(1)
plt.plot(t,psi,t,psi-sin(t),'r--')
plt.figure(2)
plt.plot(t,thetadot,'r-',t,psidot,'g-')
plt.figure(3)
plt.plot(t,h1,t,h2)
plt.show()
I have also attached the simulink file- Right Now it is throwing algebraic loop error.
6 Comments
Birdman
on 4 Apr 2018
Model can not be opened. Can you reshare it?
Amardeep Mishra
on 4 Apr 2018
Edited: Amardeep Mishra
on 4 Apr 2018
Birdman
on 4 Apr 2018
It ran without any error for me. What was the error statement? Can you share it? Where is the algebraic loop found?
Amardeep Mishra
on 4 Apr 2018
Birdman
on 4 Apr 2018
Yes, they are similar.
Amardeep Mishra
on 4 Apr 2018
Answers (1)
Birdman
on 4 Apr 2018
0 votes
For algebraic loop errors, simply add a Delay block to where the feedback occurs. This should solve it.
5 Comments
Amardeep Mishra
on 4 Apr 2018
Birdman
on 4 Apr 2018
Can you share the model which this error occurs?
Amardeep Mishra
on 4 Apr 2018
Amardeep Mishra
on 4 Apr 2018
Birdman
on 4 Apr 2018
Anyway, keep in mind to add a Delay block if algebraic loop occurs. There are other solutions, but this is the basic one.
Categories
Find more on Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!