What the F##K! ODE45! Why are you not working?!

4 views (last 30 days)
I bought this book "Numerical and Analytical Methods w/ MATLAB for Engineers & Scientists" By William Boder, and it sucks! The butt-head skips steps and I got errors using his examples. PLEASE HELP!
%This problem determines y(t)position of a mass-spring-dashpot system
%Y1 = y, Y2 = v, Y1' = Y2, Y2' = 5*t-3Y2-2Y1, for t<2,
%Y2'= -3Y2-2Y1, for t >= 2,
%y(0) = 1.0, y'(0) = 0
initial = [1.0 0.0];
tspan = 0.0:0.1:4;
[t,Y] = ode45('dYdt_laplace',tspan,initial);
Error using feval
Undefined function 'dYdt_laplace' for input arguments of type 'double'.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
What is wrong?

Answers (2)

John D'Errico
John D'Errico on 4 Apr 2015
I had to edit your post just to be able to read it. Please use the "{} Code" button to format your posted code in the future.
READ THE ERROR MESSAGE.
Did you define an m-file named dYdt_laplace.m on your search path? Clearly MATLAB is telling you that it cannot find that function. What does this tell you:
which dYdt_laplace -all

Star Strider
Star Strider on 4 Apr 2015
It may also be obsolete syntax. Assuming that you have saved your ODE function file as ‘dYdt_laplace.m’, see if:
[t,Y] = ode45(@dYdt_laplace,tspan,initial);
works.
Check the copyright date and any mention of the MATLAB versions it was written with, and check online to see if the code in the book has been updated to later versions. The algorithms in the book are probably as correct now as they were then, but MATLAB has changed significantly over the years.

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!