Can anyone tell me how to implement these timevarying state space equations in matlab

2 ビュー (過去 30 日間)
Bilal
Bilal 2014 年 10 月 22 日
回答済み: Bilal 2014 年 11 月 13 日

採用された回答

Ced
Ced 2014 年 10 月 22 日
I would use one of the ode functions, e.g. ode45. You can then define an arbitrarily complex, nonlinear, time-varying, etc. system.
In your case, something like that (parameters are rubbish, but you have those)
function [Tout, Xout] = run_ode
% Some Parameters
Rm = 1000;
Ra = 1000;
% Time-varying parts:
C = @(t)(sqrt(t+1)^3);
dC = @(t)(3*sqrt(t+1)/2);
r = @(x)x*(-x<0); % Ramp function
p = @(x)[r(x(2)-x(1))/Rm ; r(x(1)-x(4))/Ra];
% Set up simulation
dx = @(t,x)ode_sys(t,x,C(t),dC(t),p(x));
Ts = 1e-12;
t_end = 1e-10;
t_sim = 0:Ts:t_end;
x0 = randn(5,1);
[ Tout, Xout ] = ode45(dx,t_sim,x0);
end
% Define system equations
function dy = ode_sys(t,x,C,dC,p)
% Some Parameters
Rs = 100;
Cr = 1e-6;
Cs = 2*Cr;
Ca = 0.1*Cr;
Ls = 6e-9;
Rc = 1e6;
b1 = 1/(Rs*Cr);
b2 = 1/(Rs*Cs);
% Defined time-varying system matrices elementwise
Ac = [ -dC/C 0 0 0 0 ;
0 -b1 b1 0 0 ;
0 b2 -b2 0 1/Cs;
0 0 0 0 -1/Ca;
0 0 -1/Ls 1/Ls -Rc/Ls ];
Pc = [ 1/C -1/C; -1/Cr 0; 0 0 ; 0 1/Ca ; 0 0 ];
dy = Ac*x + Pc*p;
end
Cheers
  8 件のコメント
Bilal
Bilal 2014 年 10 月 22 日
from where it will get the value of tn ?
Ced
Ced 2014 年 10 月 22 日
no, you don't need to give the range of tn for ode45. You just define E the same way you do for C, dC and the rest. When you then call e.g. E(3), then the function E(t) will be evaluated at t = 3;
The integration range is then passed to ode45. In my first answer, I had used
Ts = 1e-12;
t_end = 1e-10;
t_sim = 0:Ts:t_end;
x0 = randn(5,1);
[ Tout, Xout ] = ode45(dx,t_sim,x0);
t_sim is only passed to ode45, and does not appear anywhere else. Instead of defining t_sim as a time vector with all time steps, I could also only pass [ t_start t_end ], and then ode45 output it's own time steps. The reason I prefer passing t_sim as "full vector" is that it makes things easier to plot later, but that is a personal preference.
For the derivative: Yes, calculate the derivative by hand, and then hardcode the function. There are ways to compute derivatives symbolically using the symbolic math toolbox, but that would just make things unnecessarily complicated here. I think this derivative is still ok. If you want to check that your derivative is correct, you can always use some calculator or mathematica to check your answer. Also, note that "diff" does not compute derivatives as such, but only takes the difference between the elements in your vector, e.g. diff([ 1 2 3]) would return [ 1 1 ].

サインインしてコメントする。

その他の回答 (6 件)

Bilal
Bilal 2014 年 10 月 22 日
yes you are right but the thing is E(t) is the re scaled version of En(tn) so it would definitely effect E(t) if i don't define tn anywhere if you run my code, you will see i m getting the write results as given in this paper. check the attachment
And yes if i accept the answer can we still continue communicating here. ?
  26 件のコメント
Ced
Ced 2014 年 10 月 28 日
I'm sorry, I don't understand your question(s). Why don't you just plot it? That way, you'll see how many cycles appear? So... just to e.g.
plot(Tout,Xout(3,:))
And if it's not enough/too many cycles, adapt your end time accordingly (or simply only plot a particular section of the results).
Bilal
Bilal 2014 年 10 月 29 日
編集済み: Bilal 2014 年 10 月 29 日
i have plotted them but i am getting only one cycle let me show u

サインインしてコメントする。


Bilal
Bilal 2014 年 10 月 29 日
<<
>>
  1 件のコメント
Bilal
Bilal 2014 年 10 月 29 日
編集済み: Bilal 2014 年 10 月 29 日
If u see there the time range is okay i.e 2secs in Xout plots the problem is that output doesn't repeat itself after 0.4 secs

サインインしてコメントする。


Bilal
Bilal 2014 年 10 月 29 日
  4 件のコメント
Bilal
Bilal 2014 年 10 月 29 日
okay, i got it thanks alot.
Did you find anything why i am getting only one cycle in Xout and then output gradually goes to zero
Ced
Ced 2014 年 10 月 30 日
No, I'm afraid I'm a bit caught up in work myself at the moment. I'll have a look at it if I find the time. I haven't read the paper in detail, but maybe they have something like mod(t,HR) or so? Maybe you can try to find out what function is not periodic, and if not, why.

サインインしてコメントする。


Bilal
Bilal 2014 年 10 月 31 日
This is what exactly i have done in the generation of C(t) i have use mod(t,HR) but do i need to implement it for the state space as well ? okay please get back to me when u have time. thanks

Ced
Ced 2014 年 10 月 31 日
I mean, that would certainly work. simply replace every instance of "t" by "mod(t,60/HR)" when calling ode_sys, so
dx = @(t,x)ode_sys(mod(t,60/HR),x,C(mod(t,60/HR)), ...
The question is if this makes sense. That's something you could ask your professor or discuss with some phd student. Skimming the paper, I cannot find any reference that they artificially periodicized (that's a word now ^^) their solutions. But then again, little details are often omitted (or forgotten) when describing simulations in papers.
  12 件のコメント
Bilal
Bilal 2014 年 11 月 7 日
I am unable to plot derivative of C that you told me to generate using syms. its getting mpower error

サインインしてコメントする。


Bilal
Bilal 2014 年 11 月 13 日
Please reply me back as soon as you get free. Thanks

カテゴリ

Help Center および File ExchangePulsed Waveforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by