# Unable to simulate a problem in simulink that runs effortlessly in Python.

조회 수: 5(최근 30일)
Amardeep Mishra 4 Apr 2018
댓글: Birdman 4 Apr 2018
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):
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
#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
sol=odeint(f,y0,t)
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.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

표시 이전 댓글 수: 3
Amardeep Mishra 4 Apr 2018
I have shared the graph with you. Can you check, are you getting similar results in matlab?
Birdman 4 Apr 2018
Yes, they are similar.
Amardeep Mishra 4 Apr 2018
It is constantly throwing error in my case. Here is the screenshot of algebraic loop error.

로그인 to comment.

### 답변(1개)

Birdman 4 Apr 2018
For algebraic loop errors, simply add a Delay block to where the feedback occurs. This should solve it.

#### 댓글 수: 5

표시 이전 댓글 수: 2
Amardeep Mishra 4 Apr 2018
I have already shared the model-- "gyro_model1.mdl". It is available in my original post. I have tried my problem in various versions of matlab from 2015 all the way to 2017. But the problem still persists. I dont know how you were getting correct answers in your simulink.
Amardeep Mishra 4 Apr 2018
Ok, it started working in 2017 matlab. Weird!
Birdman 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.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by