Solution of linear-time varying system in matlab

19 views (last 30 days)
ShooQ
ShooQ on 27 Jun 2022
Edited: Torsten on 27 Jun 2022
I tried the given below to get the solution of the linear-time varying equation using for-loop, but the solution is not right what I am getting using ode45. I don’t know where I am getting wrong while implementing this. Then I want to estimate the parameter g(t) using the gradient method.
r0 = 0.05;
L = 0.1;
d = 0.005;
w0 = 1.5;
Ts=10;
t=[0:Ts:800];
x0=[0 0 1]';
y0=1;
x_value=[];
for k=1:(length(t)) % Number of Iterations
x_value=[x_value x0];
g(k) = (2*r0*L*sinh((d*(k))/2))./(d*cosh((d*(k))/2)+L*sinh((d*(k))/2));
A0 = [ -0.5*g(k) -w0 0 ;
w0 -g(k)*0.5 0 ;
0 0 -g(k)];
B0 =[0; 0; -g(k)];
Q=integral(@(u) expm(A0*((k+1)*Ts)-u)*B0,(k*Ts),((k+1)*Ts), 'ArrayValued', true);
x0=expm(A0*Ts)*x0+Q;
end
plot(t,x_value(1,:),'r-','linewidth',1);
  19 Comments
Torsten
Torsten on 27 Jun 2022
Edited: Torsten on 27 Jun 2022
If these are the correct update formulae, the original code you posted was correct. You can't write A0(k)=..., B0(k) = ...; x0(k+1) = ... since the objects on the right-hand side (the ...) aren't scalar values, but vectors or matrices.
This code works, but must be wrong for the reason I already mentionned (g only depends on the loop index, but not on t):
r0 = 0.05;
L = 0.1;
d = 0.005;
w0 = 1.5;
Ts = 10;
t = 0:Ts:800;
x0=[0 0 1]';
A0=zeros(3,3);
B0=zeros(3,1);
x_value=[];
for k=1:length(t) % Number of Iterations
x_value=[x_value x0];
g = (2*r0*L*sinh((d*(k))/2))./(d*cosh((d*(k))/2)+L*sinh((d*(k))/2));
A0 = [ -0.5*g -w0 0 ;
w0 -g*0.5 0 ;
0 0 -g];
B0 =[0; 0; -g];
Q = integral(@(u) expm(A0*((k+1)*Ts)-u)*B0,(k*Ts),((k+1)*Ts), 'ArrayValued', true);
x0 = expm(A0*Ts)*x0+Q;
end
plot(t,x_value(3,:),'r-','linewidth',1);

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!