Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

Topic: How do I pass a value to a function called by ode45?
Replies: 5   Last Post: Feb 7, 2013 10:42 PM

Advanced Search

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

Posts: 113
Registered: 11/22/09
Re: How do I pass a value to a function called by ode45?
Posted: Feb 5, 2013 5:17 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Steven_Lord" <slord@mathworks.com> wrote in message <kerhrj$aeq$1@newscl01ah.mathworks.com>...
>
>
> "Jeff " <spREMOVEHITSjeffAT@SIGNoptonline.net> wrote in message
> news:kerh1u$72o$1@newscl01ah.mathworks.com...

> > I want to pass a value (beta) to a function which I'm passing to ode45,
> > but I can't quite fiigure out how to do it from the documentation. Here is
> > the current function to be passed:

>
> These examples show two approaches of how to pass additional parameters into
> the function called by FZERO; those same techniques work with ODE45.
>
> http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


Unfortunately, I cannot use nested or anonymous functions. The functions I'm calling are in separate files. I cut down the example I typed in, but basically, it uses an if..elseif block to choose a function based on other parameters.

I was able to make my sample work by adding a third parameter to the declaration of f and then using this call:
[t_steps,s1]=ode45(@(t,y) f(t,y,beta), t_steps, s0, options);

But I can't say I understand what it's doing. And I note that t and y are not given values anywhere before the @(t,y) part of that command. But the correct values are being passed into the function (at least the first time) and I'm getting the results I expect.

Thanks.



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.