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 view (last 30 days)
Show older comments
Zivile Dailidonyte
on 20 Oct 2018
Edited: madhan ravi
on 20 Oct 2018
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
0 Comments
Accepted Answer
madhan ravi
on 20 Oct 2018
Edited: madhan ravi
on 20 Oct 2018
%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 Comments
madhan ravi
on 20 Oct 2018
Edited: madhan ravi
on 20 Oct 2018
just copy my answer(full) and paste it in the command window
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!