The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: simple harmonic oscillator using ode45 function
Replies: 9   Last Post: May 28, 2013 9:04 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: simple harmonic oscillator using ode45 function
Posted: Dec 14, 2012 12:01 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Shane " <> wrote in message
> "Torsten" wrote in message <kafd1n$ah8$>...
>> "Shane" wrote in message <kaf8sj$q32$>...


> -------------------------------------------------------------------
> Thanks for the help Torsten
> I've been struggling with it since I posted the first message and I've
> gotten somewhere at least, I solved the problem first by creating two
> first order equations and tried creating a function :
> ----------code----------------
> function xp = f1(t,x)
> a=1;
> b=1;
> xp= zeros(2,1);
> xp(1)=x(2);
> xp(2)= -a*x(2) - b*x(1);

Looks correct.

> ------------------------------------------
> although when I try to run the function to evaluate the problem I always
> get an error message: ---------------code---------
> tspan=[0,50];
> init=[-2;0];
> a= 1;
> b=2;
> [t,x]=ode45(@1,tspan,init);

Is the typo (@1 instead of @f1) just in the code you posted or in your
actual code?

> {Error using <a href="matlab:helpUtils.errorDocCallback('feval')"
> style="font-weight:bold">feval</a>
> Error: <a href="matlab: opentoline('Q:\MATLAB\shm0.m',1,29)">File: shm0.m
> Line: 1 Column: 29</a>
> Unbalanced or unexpected parenthesis or bracket.

Show the group the first two or three lines of shm0.m, please. You can
easily do this by typing:

dbtype 1:3 shm0.m

and copying the output into your reply.


Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.