From: anant on
Hi,
we have expression like:

r1='(1-a0^2)*cos(t)+a0*cos(2*t)';

we have to remove the term of cos(t) and store the coefficients of it for further use.

I did like;

[coef,rest]=strtok(r1,'cos(t)');

rest=rest(10:end);

it gives rest=a0*cos(2*t) and coef=1-a0^2;

But,it is not necessary that matlab return the expression like that we have written.

Means,some time it gives like

r=a0*cos(2*t)+(1-a0^2)*cos(t) or some other order.

How can we store the coefficient if expression is not written properly.\

I am using matlab 5.3
From: us on
"anant " <kant85.shukla(a)gmail.com> wrote in message <i2jqed$f94$1(a)fred.mathworks.com>...
> Hi,
> we have expression like:
>
> r1='(1-a0^2)*cos(t)+a0*cos(2*t)';
>
> we have to remove the term of cos(t) and store the coefficients of it for further use.
>
> I did like;
>
> [coef,rest]=strtok(r1,'cos(t)');
>
> rest=rest(10:end);
>
> it gives rest=a0*cos(2*t) and coef=1-a0^2;
>
> But,it is not necessary that matlab return the expression like that we have written.
>
> Means,some time it gives like
>
> r=a0*cos(2*t)+(1-a0^2)*cos(t) or some other order.
>
> How can we store the coefficient if expression is not written properly.\
>
> I am using matlab 5.3

hmm... what ...exactly... is wrong with your solution(?)...

us
From: Walter Roberson on
anant wrote:

> we have expression like:
>
> r1='(1-a0^2)*cos(t)+a0*cos(2*t)';
>
> we have to remove the term of cos(t) and store the coefficients of it
> for further use.
>
> I did like;
>
> [coef,rest]=strtok(r1,'cos(t)');
>
> rest=rest(10:end);
>
> it gives rest=a0*cos(2*t) and coef=1-a0^2;
>
> But,it is not necessary that matlab return the expression like that we
> have written.
>
> Means,some time it gives like
>
> r=a0*cos(2*t)+(1-a0^2)*cos(t) or some other order.
>
> How can we store the coefficient if expression is not written properly.\
>
> I am using matlab 5.3

That's a fairly old version of Matlab.

Do you have the symbolic toolbox? (If you do it would be the Maple-based
one.)
From: anant on
Walter Roberson <roberson(a)hushmail.com> wrote in message <ivg3o.49157$Ls1.44878(a)newsfe11.iad>...
> anant wrote:
>
> > we have expression like:
> >
> > r1='(1-a0^2)*cos(t)+a0*cos(2*t)';
> >
> > we have to remove the term of cos(t) and store the coefficients of it
> > for further use.
> >
> > I did like;
> >
> > [coef,rest]=strtok(r1,'cos(t)');
> >
> > rest=rest(10:end);
> >
> > it gives rest=a0*cos(2*t) and coef=1-a0^2;
> >
> > But,it is not necessary that matlab return the expression like that we
> > have written.
> >
> > Means,some time it gives like
> >
> > r=a0*cos(2*t)+(1-a0^2)*cos(t) or some other order.
> >
> > How can we store the coefficient if expression is not written properly.\
> >
> > I am using matlab 5.3
>
> That's a fairly old version of Matlab.
>
> Do you have the symbolic toolbox? (If you do it would be the Maple-based
> one.)

Yes,we have symbolic toolbox.