From: Steven Lord on 9 May 2010 22:39 "Luca Turchet" <tur(a)imi.aau.dk> wrote in message news:hs55ng$rer$1(a)fred.mathworks.com... > Hi all, I ask you a syntax help because I have a problem in passing > parameters in aa function handle whithin ode45. > > > > I define a function in the file distance_integral.m: > > function [dxds] = distance_integral(s,x,mu,sigma) > > dxds = 1/sqrt(1 + gaussian_der(x, mu, sigma).^2); > > > > > Then I use such function within ODE: > > [S X] = ode45(@(s,x) distance_integral(s,x,mu,sigma),Sspan,IC) > ...but I get this error: > > ??? Attempted to access distance_integral(0,1.5,0,2); index must be a > positive integer or logical. That suggests to me that you have a variable named distance_integral in your workspace when you call ODE45. In this case, since you have both a function and a variable with that name, the anonymous function handle is choosing to treat your reference to that name as an attempt to index into the variable, not a call to the function. http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f7-58170.html#bresuvu-3 If that's the case, delete or rename that variable. The reason this wouldn't happen if you weren't choosing to pass your own mu and sigma values into the function is because your code would then look like: [S X] = ode45(@distance_integral,Sspan,IC) and the @ operator (to construct a function handle) only operates on a function name, not a variable name. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Torsten Hennig on 10 May 2010 00:50
> Hi all, > I ask you a syntax help because I have a problem in > passing parameters in aa function handle whithin > ode45. > > > > I define a function in the file distance_integral.m: > > function [dxds] = distance_integral(s,x,mu,sigma) > > dxds = 1/sqrt(1 + gaussian_der(x, mu, sigma).^2); > > The arclength of a curve is between points a and b is _not_ int_{a}^{b} 1/sqrt(1+f'(x)^2) but int_{a}^{b} sqrt(1+f'(x)^2) Best wishes Torsten. > > > > Then I use such function within ODE: > > [S X] = ode45(@(s,x) > distance_integral(s,x,mu,sigma),Sspan,IC) > > ...but I get this error: > > ??? Attempted to access distance_integral(0,1.5,0,2); > index must be a positive integer or logical. > > Error in ==> @(s,x)distance_integral(s,x,mu,sigma) > > > Error in ==> odearguments at 110 > f0 = feval(ode,t0,y0,args{:}); % ODE15I sets > args{1} to yp0. > > Error in ==> ode45 at 173 > [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, > odeArgs, odeFcn, ... > > Error in ==> John_method at 68 > [S X] = ode45(@(s,x) > distance_integral(s,x,mu,sigma),Sspan,IC) % Solve ODE > > > > > > > I think the error is due to the a syntax problem, > because if I don´t pass the values of mu and sigma > which will be used in another function (i.e. > gaussian_der) I don´t get problems. > > > Any suggestion? > > Thanks in advance > > Cheers > |