how to add feedback in matlab ?
3 ビュー (過去 30 日間)
古いコメントを表示
hello
I want to add feedback in code, means output is feeding back to input , how should i do this ? i am plotting output by using summation,
Is the code is correct means any other suggestions ?
"sum_out = Y(:,3)+Y(:,6)"
the system is as following
code
***************
function
****************
function dz = myeqd(t,y,ti,xx)
dz = zeros(6,1);
mu = 0.3;
r= sqrt(y(1)^2 + y(2)^2);
K1=500;
K2 = 500;
F=interp1(ti,xx,t);
%osc1
dz(1)= (mu - r^2)*y(1) - y(3)*y(2) +K1.*F;
dz(2) = (mu - r^2)*y(2) + y(3)*y(1);
dz(3) = (-K1.*F) * (y(2)/sqrt(y(1)^2 + y(2)^2));
%osc2
dz(4)= (mu - r^2)*y(4) - y(6)*y(5) +K2.*F;
dz(5) = (mu- r^2)*y(5) + y(6)*y(4);
dz(6) = (-K2.*F) * (y(5)/sqrt(y(4)^2 + y(5)^2));
**************************************
main code
***************************
time = 0:0.001:20;
xx = chirp(time,100,10,400,'linear');
ti=time;
[T,Y]=ode45(@(t,y) myeqd(t,y,ti,xx),time,[5;5;90;5;5;90]);
sum_out = Y(:,3)+Y(:,6);
plot (T,sum_out)
0 件のコメント
採用された回答
Jan
2013 年 2 月 12 日
As usual I want to stress, that ODE45 is designed for smooth function, but F=interp1(ti,xx,t); is not smooth. Here the changes are at least continuous, in opposite to many other examples you can find in this forum.
See e.g. http://www.mathworks.com/matlabcentral/answers/59582#answer_72047 for a description, why ODE45 can produce either bad or no results for such functions.
3 件のコメント
ChristianW
2013 年 2 月 12 日
Continuous changes, what do you mean? Smooth inputs with a converter, measurement cards, digital inputs, static friction etc?
Jan
2013 年 2 月 12 日
There is no Matlab solver, which can handle non-smooth RHS. I've added some references at the linked page.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!