how should i do adaptive tuning of parameter gain "K " mention in the function ?

Hello, I want to do adaptive tuning of gain K in the following code. At the starting time of tspan K should be more and at the end time of tspan it should be less. how should i do this ?
******************************************
%function
***************************************
function dz = myeqd(t,y,ti,fi)
dz = zeros(3,1);
mu=0.3;
r= sqrt(y(1)^2 + y(2)^2);
K=20;
F=interp1(ti,fi,t);
dz(1)= (mu - r^2)*y(1) - y(3)*y(2) +K*F;
dz(2) = (mu - r^2)*y(2) + y(3)*y(1);
dz(3) = (-K*F) * (y(2)/sqrt(y(1)^2 + y(2)^2));
**************************************************
*************
w1=20;
w2=30;
w3=40;
Tspan1=0:0.01:10;
Tspan2= 10.01:0.01:20;
Tspan3= 20.01:0.01:30;
fi1 = cos(2*pi*w1.*Tspan1);
fi2 = cos(2*pi*w2.*Tspan2);
fi3 = cos(2*pi*w3.*Tspan3);
Tspan = [Tspan1 Tspan2 Tspan3];
fi=[fi1 fi2 fi3];
ti=Tspan;
[T,Y]=ode45(@(t,y) myeqd(t,y,ti,fi),Tspan,[1;1;15]);
plot (T,Y(:,3),'r')
*********************************************

 Réponse acceptée

In your function you can use t to change the value of K
K=20-t/2
Your max(tspan ) is 30, then K will change from 20 to 20-30/2

5 commentaires

Hello Azzi,
I have done for only for one time span that is 0 to 10 secs and run the simulation.
the function --- function dz = myeqd(t,y,ti,fi)
if i am using K = 20 - ti/2 , because ti = Tspan in main code.
but i am getting following error.
********************************************************************
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in eqd1 (line 75) dz(1)= (mu - r^2)*y(1) - y(3)*y(2) +K*F;
Error in @(t,y)eqd1(t,y,ti,fi)
Error in odearguments (line 88) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in maincode1 (line 9) [T,Y]=ode45(@(t,y) eqd1(t,y,ti,fi),Tspan,[1;1;30]);
********************************************************************
why this error is coming ?
It's not K = 20 - ti/2 , it's
K = 20 - t/2
ok ..... but in the function t is related to Tspan ?
ti is a vector, each step ti is not varying, it's used to find F at time t, which vary according to tspan. And whatever is t, you just need to change the value of K. Then write
K = 20 - t/2
ok , thank you for your guidance Azzi
I will try this for more than 1 time span .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Aerospace Applications dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by