フィルターのクリア

Why my ODE is not solving?

1 回表示 (過去 30 日間)
Aung Moe Zaw
Aung Moe Zaw 2022 年 3 月 27 日
コメント済み: Aung Moe Zaw 2022 年 3 月 27 日
I'm trying to solve the ODE with an input of a cosine wave (x1) but i am not getting the output in a wave form. Please help me out. Thanks!
function [] = call_spring()
t=0:0.001:10;
y0=[0,1];
x1=2.5*cos(4*pi*t);
[t,y]=ode45(@spring,t,y0);
plot(t,y,t,x1)
function dzdt = spring(t,y)
k=342; m=2.853; x1=2.5*cos(4*pi*t);
y1=y(1);
y2=y(2);
dzdt = [y2 ; (-k/m)*(x1-y1)];
end
end

採用された回答

Sam Chak
Sam Chak 2022 年 3 月 27 日
編集済み: Sam Chak 2022 年 3 月 27 日
Because of the sign in this line. (minus) (minus) = plus. It means that energy is continuously injected into the system, and destabilizes it.
(-k/m)*(x1 - y1)
function [] = call_spring()
t = 0:0.001:10;
y0 = [0, 1];
x1 = 2.5*cos(4*pi*t);
[t, y] = ode45(@spring, t, y0);
plot(t, y, t, x1)
end
function dzdt = spring(t, y)
k = 342;
m = 2.853;
x1 = 2.5*cos(4*pi*t);
y1 = y(1);
y2 = y(2);
dzdt = [y2;
(-k/m)*(x1 + y1)];
end
Result
Also, please double check your equation. Could be this one too:
(-k/m)*y1 + (1/m)*x1
  4 件のコメント
Sam Chak
Sam Chak 2022 年 3 月 27 日
You are welcome, @Aung Moe Zaw
There are two vectors in y. To plot only the first vector, then replace
plot(t, y, t, x1)
with
plot(t, y(:,1), t, x1)
grid on
xlabel('Time, t')
ylabel('y_{1} and x_{1}')
title('Time response of y_{1}, perturbed by x_{1}')
legend('y_{1}', 'x_{1}')
Aung Moe Zaw
Aung Moe Zaw 2022 年 3 月 27 日
Thank you very much!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by