Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem with subs

Subject: problem with subs

From: deepak

Date: 28 Jun, 2010 07:12:05

Message: 1 of 7

hi,

i am using subs function to substitute the value of variable a1 in a expression

b =
(mxdd*cos(2*a1 - a2) + mg*sin(2*a1 - a2) - 6*mxdd*cos(a2) - mg*sin(a2) + mxdd*cos(2*a1 + a2))/(4*cos(a2)^2 + 2*cos(2*a1) - cos(2*a1 - 2*a2) - cos(2*a1 + 2*a2) + 4) + ((sin(a2)^2 - sin(a1)^2*sin(a2)^2)^(1/2)*(-1/(2*sin(a1)^2*sin(a2)^2 - 2))^(1/2))/sin(a2)
 
when i am using syntax
subs(b,a1,0.1)
it's returning the same expression as written above but if i am pasting whole expression instead of b ,only then it's substituting the value.

Can you please tell me what should i do so that i can substitute value without actually copy pasting the whole expression.i'm using matlab 2010a.

Thnx and regards

Deepak

Subject: problem with subs

From: us

Date: 28 Jun, 2010 07:22:05

Message: 2 of 7

"deepak " <dkjknobel@rediff.com> wrote in message <i09i05$6k9$1@fred.mathworks.com>...
> hi,
>
> i am using subs function to substitute the value of variable a1 in a expression
>
> b =
> (mxdd*cos(2*a1 - a2) + mg*sin(2*a1 - a2) - 6*mxdd*cos(a2) - mg*sin(a2) + mxdd*cos(2*a1 + a2))/(4*cos(a2)^2 + 2*cos(2*a1) - cos(2*a1 - 2*a2) - cos(2*a1 + 2*a2) + 4) + ((sin(a2)^2 - sin(a1)^2*sin(a2)^2)^(1/2)*(-1/(2*sin(a1)^2*sin(a2)^2 - 2))^(1/2))/sin(a2)
>
> when i am using syntax
> subs(b,a1,0.1)
> it's returning the same expression as written above but if i am pasting whole expression instead of b ,only then it's substituting the value.
>
> Can you please tell me what should i do so that i can substitute value without actually copy pasting the whole expression.i'm using matlab 2010a.
>
> Thnx and regards
>
> Deepak

one of the solutions
- make sure your B is a SYMbolic var...

     class(b)
% ans = sym % <- !

us

Subject: problem with subs

From: deepak

Date: 28 Jun, 2010 07:29:05

Message: 3 of 7

B is symbolic in my case still i am facing the priblem

> one of the solutions
> - make sure your B is a SYMbolic var...
>
> class(b)
> % ans = sym % <- !
>
> us

Subject: problem with subs

From: us

Date: 28 Jun, 2010 10:01:07

Message: 4 of 7

"deepak " <dkjknobel@rediff.com> wrote in message <i09j01$add$1@fred.mathworks.com>...
> B is symbolic in my case still i am facing the priblem
>
> > one of the solutions
> > - make sure your B is a SYMbolic var...
> >
> > class(b)
> > % ans = sym % <- !
> >
> > us

ok...
now, here SUBS yields this result

     s=[
          '(mxdd*cos(2*a1 - a2) + mg*sin(2*a1 - a2) - 6*mxdd*cos(a2) - mg*sin(a2)',...
          ' + mxdd*cos(2*a1 + a2))/(4*cos(a2)^2 + 2*cos(2*a1) - cos(2*a1 - 2*a2)',...
          ' - cos(2*a1 + 2*a2) + 4) + ((sin(a2)^2 - sin(a1)^2*sin(a2)^2)^(1/2)*',...
          '(-1/(2*sin(a1)^2*sin(a2)^2 - 2))^(1/2))/sin(a2)'
     ];
     b=sym(s);
     r=subs(b,'a1',.01)
%{
% r =
(mxdd*cos(1/50 - a2) + mg*sin(1/50 - a2) - 6*mxdd*cos(a2) - mg*sin(a2) + mxdd*cos(a2 + 1/50))/(4*cos(a2)^2 + 2*cos(1/50) - cos(1/50 - 2*a2) - cos(2*a2 + 1/50) + 4) + ((-1/(2*sin(1/100)^2*sin(a2)^2 - 2))^(1/2)*(sin(a2)^2 - sin(1/100)^2*sin(a2)^2)^(1/2))/sin(a2)
%}

us

Subject: problem with subs

From: deepak

Date: 28 Jun, 2010 12:05:21

Message: 5 of 7

thanks ,it works .

can you please how to get values in decimal form coz after substitution i'm gettin some thing like cos(1/5). how can i get numeric values instead of it and that too in decimal format.


thnx again :)

Subject: problem with subs

From: Steven Lord

Date: 28 Jun, 2010 13:44:15

Message: 6 of 7


"deepak " <dkjknobel@rediff.com> wrote in message
news:i0a361$44i$1@fred.mathworks.com...
> thanks ,it works .
>
> can you please how to get values in decimal form coz after substitution
> i'm gettin some thing like cos(1/5). how can i get numeric values instead
> of it and that too in decimal format.

HELP VPA.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: problem with subs

From: us

Date: 28 Jun, 2010 16:28:07

Message: 7 of 7

"deepak " <dkjknobel@rediff.com> wrote in message <i0a361$44i$1@fred.mathworks.com>...
> thanks ,it works .
>
> can you please how to get values in decimal form coz after substitution i'm gettin some thing like cos(1/5). how can i get numeric values instead of it and that too in decimal format.
>
>
> thnx again :)

a hint:

     help vpa;
     help digits; % <- a helper...

us

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us