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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive 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