Prev: Pi approximation function optimization
Next: Optimization with a variable of very huge dimension.
From: viswanath on 12 Mar 2010 21:33 Hi I have a problem in differentiating my equ. my .m file is function [t,xdot] = formdiffeq(t,XX,h,BB,A) x=zeros(1,6); y=zeros(1,6); d=zeros(6); s=zeros(6); l=zeros(6); k=zeros(1,6); %i use all these variables to calculate 'l' L=kron(l,eye(4)); xdot=A*XX+BB*L*(XX-h); end and in the command window I have calculated BB,h,A and the intial conditions as XX=[5;0;6;0;4;0;3;0;9;0;8;0;10;0;1;0;8;0;2;0;9;0;7;0]; [t,XX]=ode45(@formdiffeq,tspan,XX,[],h,BB,A); And the error i get is ??? Error using ==> odearguments at 116 FORMDIFFEQ returns a vector of length 1, but the length of initial conditions vector is 24. The vector returned by FORMDIFFEQ and the initial conditions vector must have the same number of elements. Error in ==> ode45 at 173 [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ... but the size of A and BB are 24*24 and XX is 24*1 and h is 24*1 I dnt know why I am getting this error even if the length of my intial conditions is 24 Can anyone suggest on this? Thank you
From: Steven Lord on 15 Mar 2010 11:36 "viswanath " <vishwa_viswanath(a)yahoo.com> wrote in message news:hneth2$1o6$1(a)fred.mathworks.com... > Hi > > I have a problem in differentiating my equ. my .m file is > function [t,xdot] = formdiffeq(t,XX,h,BB,A) > x=zeros(1,6); > y=zeros(1,6); > d=zeros(6); > s=zeros(6); > l=zeros(6); > k=zeros(1,6); > %i use all these variables to calculate 'l' > L=kron(l,eye(4)); > xdot=A*XX+BB*L*(XX-h); > end > > and in the command window > I have calculated BB,h,A and the intial conditions as > XX=[5;0;6;0;4;0;3;0;9;0;8;0;10;0;1;0;8;0;2;0;9;0;7;0]; > [t,XX]=ode45(@formdiffeq,tspan,XX,[],h,BB,A); > > And the error i get is > ??? Error using ==> odearguments at 116 > FORMDIFFEQ returns a vector of length 1, but the length of initial > conditions vector > is 24. The vector returned by FORMDIFFEQ and the initial conditions vector > must have > the same number of elements. > > Error in ==> ode45 at 173 > [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ... > > but the size of A and BB are 24*24 and XX is 24*1 and h is 24*1 > > I dnt know why I am getting this error even if the length of my intial > conditions is 24 Your ODE function (formdiffeq in this case) must return a vector the same size as your initial condition vector. Does it? The error message you received would suggest that it does not. Only you know what sizes h, BB, and A are so only you know how to correct your expression for xdot to use the correct sizes. Just as a guess, though, I think you might need to use elementwise multiplication (.*) instead of matrix multiplication (*) for some or all of the parts of that line in formdiffeq. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: Pi approximation function optimization Next: Optimization with a variable of very huge dimension. |