From: Michael Hosea on
I don't see anything wrong with that function. The problem is probably
elsewhere.
--
Mike

"Shakeel" <shakeelj2k(a)yahoo.com> wrote in message
news:i0bul4$k57$1(a)fred.mathworks.com...
> "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message
> <i00156$1ua$1(a)fred.mathworks.com>...
>> Well, if FRBwRIG is defined in MATLAB and not in the Embedded MATLAB
>> block, I might write it something like:
>>
>> function [x,t] = RK4step(dfun,x,h,t,varargin)
>> ho2 = h/2;
>> k1 = dfun(x,t,varargin{:});
>> k2 = dfun(x + ho2*k1,t+ho2,varargin{:});
>> k3 = dfun(x + ho2*k2,t+ho2,varargin{:});
>> k4 = dfun(x + ho2*k3,t+h,varargin{:});
>> x = x + h*(k1 + 2*(k2+k3) + k4)/6;
>> t = t + h;
>>
>> Then, assuming the function FRBwRIG is only defined in MATLAB (i.e.,
>> assuming you can't just inline its definition in Embedded MATLAB
>> compliant code in the definition of dfun), I would define (in the same
>> Embedded MATLAB block):
>>
>> function dy = dfun(t,y,varargin)
>> eml.extrinsic('FRBwRIG');
>> dy = zeros(size(y));
>> dy = FRBwRIG(t,y,varargin{:});
>>
>> The call site at the top level in the Embedded MATLAB block would look
>> something like
>>
>> [x,t] = RK4step(@dfun, x, dT/nInt, t,inr, invInr, torque, uRIG, nRWRIG,
>> nBRIG, betaRIG);
>>
>> --
>> Mike
>>
>> "Shakeel" <shakeelj2k(a)yahoo.com> wrote in message
>> news:hvvfkp$hcf$1(a)fred.mathworks.com...
>> > "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message
>> > <hvtsa7$3q4$1(a)fred.mathworks.com>...
>> >> Well, this is pretty old MATLAB code and not written in a good style.
>> >>
>> >> For starters, don't cobble together strings and call "eval". Function
>> >> handles work. Just use them directly--no strings. Use varargin to
>> >> handle the extra parameters. You'll probably have better luck writing
>> >> something from scratch. For some examples of using function handles
>> >> for things of this nature, see
>> >>
>> >> http://www.mathworks.com/moler/ncm/ode23tx.m
>> >>
>> >> There are things in there that are not Embedded MATLAB compliant, and
>> >> it is a variable-step size implementation, which makes it a lot more
>> >> complicated than RK4, but especially observe how the stages s1, s2,
>> >> and s3 are computed, e.g.
>> >>
>> >> s1 = F(t, y, varargin{:});
>> >> ...
>> >> s2 = F(t+h/2, y+h/2*s1, varargin{:});
>> >> s3 = F(t+3*h/4, y+3*h/4*s2, varargin{:});
>> >> tnew = t + h;
>> >> ynew = y + h*(2*s1 + 3*s2 + 4*s3)/9;
>> >>
>> >>
>> >> Your code should look something like that, except that it should
>> >> embody the 4th order Runge-Kutta method instead of the
>> >> Bogacki-Shampine pair.
>> >> --
>> >> Mike
>> >>
>> >>
>> > thanks mike for your help.please guide further
>> >
>> > let suppose I further simplify my RK4 file to make at least compliant
>> > so that I can get code compile in simulink for matlab 2007 for my DSP
>> > board.
>> > my.mdl is as now has the line below in the first argument ' ' instead
>> > of @.
>> > x = RK4('FRBwRIG', x, dT/nInt, t,inr, invInr, torque, uRIG,
>> > nRWRIG, nBRIG, betaRIG);
>> >
>> > I have changed RK4.m is as follows
>> >
>> > k1=zeros(13,1);
>> > k2=zeros(13,1);
>> > k3=zeros(13,1);
>> > k4=zeros(13,1);
>> > k1 = feval([FRBwRIG(x,t,p1,p2,p3,p4,p5,p6,p7)]); k2 =
>> > feval([FRBwRIG(x + ho2*k1,t+ho2,p1,p2,p3,p4,p5,p6,p7)]);
>> > k3 = feval([FRBwRIG(x + ho2*k2,t+ho2,p1,p2,p3,p4,p5,p6,p7)]);
>> > k4 = eval([FRBwRIG(x + ho2*k3,t+h,p1,p2,p3,p4,p5,p6,p7)]);
>> > x = x + h*(k1 + 2*(k2+k3) + k4)/6;
>> > %end of RK4 function code
>> > I also used eval instead of feval and make it eml.extrinsic('eval')
>> > but still I am getting the following error
>> > assertion error: state flow
>> > error: ------------------>differ_ones_only(message)
>> > I shall be grateful for your help
>> > thanks and best regards
>>
> Hi Mike
>
> Thanks a lot for your help
>
> I have done what you suggested in above ,all the code is now compiling but
> the now simulation stopped due to array read bound error.My code uses
> myfind function as you know embedded matlab does not support find function
> that is why i have used the following in-line myfind function
> %%%%%myfind function%%%%%%
> function [idx,n] = myfind(b)
> % FIND-like function.
> % Input B is a logical array.
> % Output IDX is a column vector with numel(b) elements.
> % Output N is the number of elements of IDX in use.
> n = double(0);
> idx = zeros(numel(b),1,'double');
> for k = 1:numel(b)
> if b(k)
> n = n + 1;
> idx(n) = k;
> end
> end %%%%%%end%%%%%%%%%%%%%%%
> this function causes array read bound error i.e I am running simulation
> for 4800 times and during the running of the simulation a variable(is
> actually structure) named sensorData.valid=[ 1 1] is accessing 0 index
> ,that is why I am getting array bound read error.
>
> will you help to correct this myfind function.If I use matlab find
> function then there is problem of mxarray indexing is not allowed,that is
> why I have used myfind function
>
> any help will be appreciated
> Thanks in Advance again


From: Shakeel on

Dear Mike I have another problem for discussion

I have configured in simulink options both the real-time workshop and embedded matlab IDE to set up code composer studio project generation i.e link for CCS grt TMS 320 platform. and link for CCS. during build project lccmake.exe being used which is causing error somtimes.

but I dont know how to use the generated for my hardware. please guide how to use the generated C or H files by embedded matlab.

the overall objective is as follows

I have hardware board for Ti DSP320C6713 on which I am supposing that when I generate C code using my embedded matlab function in the simulink with the option of generating the CCS(code composer studio ) project. then I use this generated project in code composer stdio and download the code after compiling in CCS to my hardware and see the code running in action.

please correct the steps of the above objective where required and guide in details.

I shall be grateful to you for all yoru efforts

Shakeel
"Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message <i0c2nm$b70$1(a)fred.mathworks.com>...
> I don't see anything wrong with that function. The problem is probably
> elsewhere.
> --
> Mike
>
> "Shakeel" <shakeelj2k(a)yahoo.com> wrote in message
> news:i0bul4$k57$1(a)fred.mathworks.com...
> > "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message
> > <i00156$1ua$1(a)fred.mathworks.com>...
> >> Well, if FRBwRIG is defined in MATLAB and not in the Embedded MATLAB
> >> block, I might write it something like:
> >>
> >> function [x,t] = RK4step(dfun,x,h,t,varargin)
> >> ho2 = h/2;
> >> k1 = dfun(x,t,varargin{:});
> >> k2 = dfun(x + ho2*k1,t+ho2,varargin{:});
> >> k3 = dfun(x + ho2*k2,t+ho2,varargin{:});
> >> k4 = dfun(x + ho2*k3,t+h,varargin{:});
> >> x = x + h*(k1 + 2*(k2+k3) + k4)/6;
> >> t = t + h;
> >>
> >> Then, assuming the function FRBwRIG is only defined in MATLAB (i.e.,
> >> assuming you can't just inline its definition in Embedded MATLAB
> >> compliant code in the definition of dfun), I would define (in the same
> >> Embedded MATLAB block):
> >>
> >> function dy = dfun(t,y,varargin)
> >> eml.extrinsic('FRBwRIG');
> >> dy = zeros(size(y));
> >> dy = FRBwRIG(t,y,varargin{:});
> >>
> >> The call site at the top level in the Embedded MATLAB block would look
> >> something like
> >>
> >> [x,t] = RK4step(@dfun, x, dT/nInt, t,inr, invInr, torque, uRIG, nRWRIG,
> >> nBRIG, betaRIG);
> >>
> >> --
> >> Mike
> >>
> >> "Shakeel" <shakeelj2k(a)yahoo.com> wrote in message
> >> news:hvvfkp$hcf$1(a)fred.mathworks.com...
> >> > "Michael Hosea" <Michael.Hosea(a)mathworks.com> wrote in message
> >> > <hvtsa7$3q4$1(a)fred.mathworks.com>...
> >> >> Well, this is pretty old MATLAB code and not written in a good style.
> >> >>
> >> >> For starters, don't cobble together strings and call "eval". Function
> >> >> handles work. Just use them directly--no strings. Use varargin to
> >> >> handle the extra parameters. You'll probably have better luck writing
> >> >> something from scratch. For some examples of using function handles
> >> >> for things of this nature, see
> >> >>
> >> >> http://www.mathworks.com/moler/ncm/ode23tx.m
> >> >>
> >> >> There are things in there that are not Embedded MATLAB compliant, and
> >> >> it is a variable-step size implementation, which makes it a lot more
> >> >> complicated than RK4, but especially observe how the stages s1, s2,
> >> >> and s3 are computed, e.g.
> >> >>
> >> >> s1 = F(t, y, varargin{:});
> >> >> ...
> >> >> s2 = F(t+h/2, y+h/2*s1, varargin{:});
> >> >> s3 = F(t+3*h/4, y+3*h/4*s2, varargin{:});
> >> >> tnew = t + h;
> >> >> ynew = y + h*(2*s1 + 3*s2 + 4*s3)/9;
> >> >>
> >> >>
> >> >> Your code should look something like that, except that it should
> >> >> embody the 4th order Runge-Kutta method instead of the
> >> >> Bogacki-Shampine pair.
> >> >> --
> >> >> Mike
> >> >>
> >> >>
> >> > thanks mike for your help.please guide further
> >> >
> >> > let suppose I further simplify my RK4 file to make at least compliant
> >> > so that I can get code compile in simulink for matlab 2007 for my DSP
> >> > board.
> >> > my.mdl is as now has the line below in the first argument ' ' instead
> >> > of @.
> >> > x = RK4('FRBwRIG', x, dT/nInt, t,inr, invInr, torque, uRIG,
> >> > nRWRIG, nBRIG, betaRIG);
> >> >
> >> > I have changed RK4.m is as follows
> >> >
> >> > k1=zeros(13,1);
> >> > k2=zeros(13,1);
> >> > k3=zeros(13,1);
> >> > k4=zeros(13,1);
> >> > k1 = feval([FRBwRIG(x,t,p1,p2,p3,p4,p5,p6,p7)]); k2 =
> >> > feval([FRBwRIG(x + ho2*k1,t+ho2,p1,p2,p3,p4,p5,p6,p7)]);
> >> > k3 = feval([FRBwRIG(x + ho2*k2,t+ho2,p1,p2,p3,p4,p5,p6,p7)]);
> >> > k4 = eval([FRBwRIG(x + ho2*k3,t+h,p1,p2,p3,p4,p5,p6,p7)]);
> >> > x = x + h*(k1 + 2*(k2+k3) + k4)/6;
> >> > %end of RK4 function code
> >> > I also used eval instead of feval and make it eml.extrinsic('eval')
> >> > but still I am getting the following error
> >> > assertion error: state flow
> >> > error: ------------------>differ_ones_only(message)
> >> > I shall be grateful for your help
> >> > thanks and best regards
> >>
> > Hi Mike
> >
> > Thanks a lot for your help
> >
> > I have done what you suggested in above ,all the code is now compiling but
> > the now simulation stopped due to array read bound error.My code uses
> > myfind function as you know embedded matlab does not support find function
> > that is why i have used the following in-line myfind function
> > %%%%%myfind function%%%%%%
> > function [idx,n] = myfind(b)
> > % FIND-like function.
> > % Input B is a logical array.
> > % Output IDX is a column vector with numel(b) elements.
> > % Output N is the number of elements of IDX in use.
> > n = double(0);
> > idx = zeros(numel(b),1,'double');
> > for k = 1:numel(b)
> > if b(k)
> > n = n + 1;
> > idx(n) = k;
> > end
> > end %%%%%%end%%%%%%%%%%%%%%%
> > this function causes array read bound error i.e I am running simulation
> > for 4800 times and during the running of the simulation a variable(is
> > actually structure) named sensorData.valid=[ 1 1] is accessing 0 index
> > ,that is why I am getting array bound read error.
> >
> > will you help to correct this myfind function.If I use matlab find
> > function then there is problem of mxarray indexing is not allowed,that is
> > why I have used myfind function
> >
> > any help will be appreciated
> > Thanks in Advance again
>