An error occurred while propagating data type 'double' through...

Dear
I'm doing an iterative algorithm in MATLAB/Simulink/Matalb Function. However, when i run the simulation, the errors occurred.(please see the attached picture and code). If possible, please help me. Thank you very much for your help.
function gamma = cg(gamma0,voutx,tao,e1,e2,M)
beta1=gamma0(1);
beta2=gamma0(2);
beta3=gamma0(3);
beta4=gamma0(4);
beta5=gamma0(5);%gamma0 is a vector.
xd=20;%设定位置x
T=0.01;%积分步长
falf=fal(tao,0.5,0.1);
fal1=dfal(e1,0.7,0.1);
fal2=dfal(e2,0.95,0.1);
b0=1;
k=1;
N=100000;%times maximum
epsilon=1e-5;%parameter
gamma=gamma0;
while(k<N)
g=gradient(xd,voutx,fal1,fal2,falf,T,b0,M,gamma);%gradient
beta1=beta1-2*(xd-voutx)*M*(beta4*fal1*T*tao)/(1+(beta4*fal1*T+beta5*fal2)*T*b0);
beta2=beta2-2*(xd-voutx)*M*T*falf*(beta4*fal1*T+beta5*fal2)/(1+(beta4*fal1*T+beta5*fal2)*T*b0);
beta3=beta3-2*(xd-voutx)*M*((beta4*fal1*T+beta5*fal2)*T*T+T/b0)*falf/(1+(beta4*fal1*T+beta5*fal2)*T*b0);
beta4=beta4-2*(xd-voutx)*M*fal1/(1+(beta4*fal1*T+beta5*fal2)*T*b0);
beta5=beta5-2*(xd-voutx)*M*fal2/(1+(beta4*fal1*T+beta5*fal2)*T*b0);%the three parameters that need to be adjusted
gamma=[beta1;beta2;beta3;beta4;beta5];%vector
if(norm(g)<epsilon), break; end
end

19 Comments

Were there other error messages as well?
Dear
After I ran the model, it only showed the errors in the first Figure, and there was no other error information. My idea is to optimize the parameters of ADRC and I will show you the complete model now.@Walter Roberson
The "complete model" doesn't help to show the error. The error indicates there is a "chart" and points to the place, "ADRC_dingdian.../cgadrc2". Click that link and where does it lead to in the model? Show all block names to help identifying the model blocks.
Dear
Sorry. All block names have been shown in the picture. When uploading the picture, I modified the name of the blocks. I re-simulated after unifying the name, but the same error is still displayed.I click the link and it leads to the MATLAB function 'frcg'. Thank you! @Fangjun Jiang@Walter Roberson
Open the MATLAB Function block code, click "edit data" to see if there is anything obvious regarding the data types of the parameters and signals.
The code seems to have problems.
  1. In the while loop, k never increases so it is an infinite loop. You need to add k=k+1
  2. the usage of gradient() function is puzzling. xd is a constant. Why there are so many input arguments?
Dear
I modify the code according to your comments.I click "edit data" and change the 'DataType' to 'double'. Then the errors are solved. However, a new error appears:
"Output argument 'gamma' is not assigned on some execution paths."
My 'gamma' is the output of the matlab function, but my output is not in the if-else statement. If possible, please help me. Thank you. @Fangjun Jiang
function gamma=frcg(gamma0,voutx,tao,e1,e2,M)
k=0;
n=length(gamma0);
N = 10000;
epsilon = 1e-5;
xd=20;
T=0.01;
b0=1;
falf=fal(tao,0.5,0.1);
fal1=dfal(e1,0.7,0.1);
fal2=dfal(e2,0.95,0.1);
g0=zeros(5,1);
d0=zeros(5,1);
while(k<N)
g=tidu(xd,voutx,fal1,fal2,falf,T,b0,M,gamma0,tao);
itern=k-(n+1)*floor(k/(n+1));
itern=itern+1;
if(itern==1)
d=-g;
else
beta=(g'*g)/(g0'*g0);
d=-g+beta*d0; gd=g'*d;
if(gd>=0.0)
d=-g;
end
end
if(norm(g)<epsilon), break; end
alpha=-(g'*d)/(d'*d);
gamma0=gamma0+alpha*d;
g0=g; d0=d;
k=k+1;
gamma=gamma0;
end
There is one possibility. If "if(norm(g)<epsilon), break; end" is satisfied during the first iteration, then gamma is never assigned.
Add "gamma=gamma0" as the first line of the function as the default return value to resolve this error.
Dear
I have added "gamma=gamma0" as the first line of the function, however, the function does't work. The error is the same as former. The change has been mentioned with '%' in the attached code. If possible, please help me. Thank you!@Fangjun Jiang
function gamma=frcg(gamma0,voutx,tao,e1,e2,M)
k=0;
n=length(gamma0);
N = 10000;
epsilon = 1e-5;
xd=20;
T=0.01;
b0=1;
falf=fal(tao,0.5,0.1);
fal1=dfal(e1,0.7,0.1);
fal2=dfal(e2,0.95,0.1);
g0=zeros(5,1);
d0=zeros(5,1);
g=g0;
while (k<N)
gamma=gamma0;%I have added this statement to the first line of 'while'.
g=tidu(xd,voutx,fal1,fal2,falf,T,b0,M,gamma0,tao);
itern=k-(n+1)*floor(k/(n+1));
itern=itern+1;
if(itern==1)
d=-g;
else
beta=(g'*g)/(g0'*g0);
d=-g+beta*d0; gd=g'*d;
if(gd>=0.0)
d=-g;
end
end
if norm(g)>epsilon, break; end
alpha=-(g'*d)/(d'*d);
gamma0=gamma0+alpha*d;
g0=g; d0=d;
k=k+1;
%gamma=gamma0; This statement has been moved to the firat line.
end
Not like that!
Use your previous version of code
Add "gamma=gamma0" as the first line of the function, which means, right below the "function gamma=frcg(gamma0,voutx,tao,e1,e2,M)" line.
Dear
I am sorry for misunderstanding your comments.
I modified the code according to your comments. The previous error was indeed resolved, but there is a new one.(please see the attached figure)
I have an ideal: Is it because it may exponentiate negative numbers that it produces complex value?(e.g. a^b: a<0, b is fraction)
I have put the 'tidu' functionn, 'fal' function and 'dfal' function behind main function. If possible, please help me. Thank you ! @Fangjun Jiang@Walter Roberson
function gamma=frcg(gamma0,voutx,tao,e1,e2,M)
gamma=gamma0;%I have added this statement to the first line.
k=0;
n=length(gamma0);
N = 10000;
epsilon = 1e-5;
xd=20;
T=0.01;
b0=1;
falf=fal(tao,0.5,0.1);
fal1=dfal(e1,0.7,0.1);
fal2=dfal(e2,0.95,0.1);
g0=zeros(5,1);
d0=zeros(5,1);
while (k<N)
g=tidu(xd,voutx,fal1,fal2,falf,T,b0,M,gamma0,tao);
itern=k-(n+1)*floor(k/(n+1));
itern=itern+1;
if(itern==1)
d=-g;
else
beta=(g'*g)/(g0'*g0);
d=-g+beta*d0; gd=g'*d;
if(gd>=0.0)
d=-g;
end
end
if(norm(g)<epsilon), break; end
alpha=-(g'*d)/(d'*d);
gamma0=gamma0+alpha*d;
g0=g; d0=d;
k=k+1;
gamma=gamma0;
end
%tidu function
function g=tidu(xd,voutx,fal1,fal2,falf,T,b0,M,gammak,tao)
g1k=(gammak(4)*fal1*T*tao)/(1+(gammak(4)*fal1*T+gammak(5)*fal2)*T*b0);
g2k=T*falf*(gammak(4)*fal1*T+gammak(5)*fal2)/(1+(gammak(4)*fal1*T+gammak(5)*fal2)*T*b0);
g3k=((gammak(4)*fal1*T+gammak(5)*fal2)*T*T+T/b0)*falf/(1+(gammak(4)*fal1*T+gammak(5)*fal2)*T*b0);
g4k=fal1/(1+(gammak(4)*fal1*T+gammak(5)*fal2)*T*b0);
g5k=fal2/(1+(gammak(4)*fal1*T+gammak(5)*fal2)*T*b0);
g = -2*(xd-voutx)*M*[g1k;g2k;g3k;g4k;g5k];
%dfal functionn
function y=dfal(x,alpha,delta)
if x>delta
y=alpha*x^(alpha-1);
else if x<-delta
y=(-1)^(alpha+1)*alpha*x^(alpha+1);
else
y=delta^(alpha-1);
end
end
end
%fal function
function y=fal(x,alpha,delta)
if abs(x)>delta
y=abs(x)^alpha*sign(x);
else
y=x/(delta^(1-alpha));
end
end
Yes, negative to a fraction needs complex numbers.
Do complex numbers make sense for the physics involved?
No. As far as I know, the complex numbers doesn't make sense for the research I've done. May I ask how to solve this problem?Thank you ! @Walter Roberson
Check the dfal() function. I think the output y is supposed to be symmetric to the input x. Your function is NOT.
Check the literature to make sure it is implemented correctly. Plot out dfal() vs. x to verify.
Dear
I modified the code according to your comments. The previous error was indeed resolved, but there is a new one.(please see the attached figure 1)
After I click 'fix' in figure 1 and run it again, the same error is still reported, but it seems that the error type has swapped, but there is still an error (please see the red box in the error figure 2).
I click the blue link and find that it points to the block 'derivative'.(please see figure 3)
May I ask what is the reasonfor this? If possible, please help me. Thank you! @Walter Roberson@Fangjun Jiang
  1. The direct derivative (du/dt) operation usually would cause problem in digital simulation. Use an approximation of derivative if it is absolutely needed. In your model, two derivatives are multiplied but I didn't see where it is used. If it is for observation only, then delete or comment out all of them.
  2. In the solver settings, reduce the step size or reduce the relative tolerance, you might be able to get the simulation running without error.
  3. If there is a true algebraic loop, you need to find it and resolve it.
  4. ADRC is known to have digital simulation stability issues due to its non-linearity. Check the literature to see if there is recommendation on the settings for Simulink simulation.
Dear
Thank you for your comments!
What I want to do is the derivative of the system output x with respect to the output of the ADRC, which I then convert to the product of the two derivatives with respect to time, as shown in Figure 1.
The product of the two derivatives is used in the subsystem 'cg1', The content of the subsystem can be seen in figure 2.
I will modify and check my model according to your comments. If I still have questions, I will come back to you. I hope that you can answer me by then. Thank you!
Best Regards!
Dear
I am so sorry to bother you again!
Over the past days, I checked the model and code according to your comments. The idea of the derivatives can be seen in my previous response on 23rd July 2022. I have turned the relative tolerance down to 1e-7, but it still reported same errors.
Now, I'm still doing my best to modify my model. At the same time, I also sent you the model, and I hope you can help me take a look.
I have put my file in the attachment 'test_model.zip' and you can download it to check. When running, you should run the m-files first. My MATLAB version is 2018b. If possible, please help me. Thank you for your help!@Fangjun Jiang@Walter Roberson
This is probably where the help from this community ends. The simulation of the Simulink model runs but it is extremely slow and it stopped due to instability of the simulation. You need to consult the expert in your field to resolve the problem. Most likely the parameters of the ADRC is too aggressive. Avoid directly derivative.
Dear
Thank you for your time and effort you have put into my problems. Your help is of great significance for me to solve the problem. I will continue to do my best to resolve these errors. Thank you again!@Fangjun Jiang
Wish you every success!

Sign in to comment.

Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Asked:

on 16 Jul 2022

Commented:

on 26 Jul 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!