Search All of the Math Forum:

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

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

 Messages: [ Previous | Next ]
 Shane Posts: 5 Registered: 12/14/12
Re: simple harmonic oscillator using ode45 function
Posted: Jan 24, 2013 9:08 AM

"Steven_Lord" <slord@mathworks.com> wrote in message <kafm1a\$c49\$1@newscl01ah.mathworks.com>...
>
>
> "Shane " <shane_t@hotmail.co.uk> wrote in message
> news:kafkjk\$7jb\$1@newscl01ah.mathworks.com...

> > "Torsten" wrote in message <kafd1n\$ah8\$1@newscl01ah.mathworks.com>...
> >> "Shane" wrote in message <kaf8sj\$q32\$1@newscl01ah.mathworks.com>...
>
> *snip*
>

> > -------------------------------------------------------------------
> > 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
>
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
> http://www.mathworks.com

---------------------------------------------------------------------------------------------------
Hi Steve
back after the winter break seen your help this is the code you asked for:
>> dbtype 1:3 shm0.m

1 tspan=[0 50];
2 init=[-2 0];
3 [t,x]= ode45(shm0,tspan,init)

>>

Thanks Shane

Date Subject Author
12/14/12 Shane
12/14/12 Torsten
12/14/12 Shane
12/14/12 Steven Lord
1/24/13 Shane
1/24/13 Steven Lord
1/24/13 Shane
12/14/12 Steven Lord
4/16/13 Benjimon
5/28/13 Shane