I have this script to plot the solution to damped oscillator but when i run it it says undefined function or variable. What am I missing?

1 回表示 (過去 30 日間)
function yp=forced(t,y)
yp=[y(2);((0.56*sin(3.7*t))-(0.78*y(2))-(14*y(1)))];
tspan=[0 5];
y0=[0,0];
[t,y]=ode45(@(t,y) forced(t,y), tspan,y0);
plot(t,y(:,1));
grid on
xlabel('time')
ylabel('displacement')
title('displacement vs time')
end

採用された回答

madhan ravi
madhan ravi 2018 年 10 月 20 日
編集済み: madhan ravi 2018 年 10 月 20 日
%SCRIPT FILE
tspan=[0 5];
y0=[0,0];
[t,y]=ode45(@forced, tspan,y0);
plot(t,y(:,1));
grid on
xlabel('time')
ylabel('displacement')
title('displacement vs time')
%FUNCTION FILE:
function yp=forced(t,y)
yp=[y(2);((0.56*sin(3.7*t))-(0.78*y(2))-(14*y(1)))];
end
  3 件のコメント
Zivile Dailidonyte
Zivile Dailidonyte 2018 年 10 月 20 日
That is exactly what I need but still when I run it it says undefined function or variable. Even though I created separate function file and the script with all the inputs.
madhan ravi
madhan ravi 2018 年 10 月 20 日
編集済み: madhan ravi 2018 年 10 月 20 日
just copy my answer(full) and paste it in the command window

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by