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:
Change symbols back to numbers

Subject: Change symbols back to numbers

From: Sheida

Date: 21 Oct, 2010 20:33:04

Message: 1 of 4

Hi I am trying to solve an equation (to eventually put in a loop). However, after I take care of the differentiating, I cannot replace the symbols with actual numbers. Could someone please help me?
Here is what my m file looks like:
syms u1 u2
f = [(u1^3) - u2; (u2^3) - u1];
u = [u1;u2];
J = jacobian(f,u);
Ji = inv(J);
b = Ji*f;
 u1 = 2;
 u2 = 1;
    u = u - b

my result for "u" is:
u =
 
 u1 + (u1 - u2^3)/(9*u1^2*u2^2 - 1) + (3*u2^2*(u2 - u1^3))/(9*u1^2*u2^2 - 1)
 u2 + (u2 - u1^3)/(9*u1^2*u2^2 - 1) + (3*u1^2*(u1 - u2^3))/(9*u1^2*u2^2 - 1)

I want matlab to replace all u1s with 2 and all u2s with 1. I have been searching for the past couple of hours and have not found anything. It doesn't seem like it is too hard but I just cant figure it out!
Thanks!

Subject: Change symbols back to numbers

From: John

Date: 21 Oct, 2010 22:15:07

Message: 2 of 4

"Sheida " <s.d.not.this@gmail.com> wrote in message <i9q820$3h$1@fred.mathworks.com>...
> Hi I am trying to solve an equation (to eventually put in a loop). However, after I take care of the differentiating, I cannot replace the symbols with actual numbers. Could someone please help me?
> Here is what my m file looks like:
> syms u1 u2
> f = [(u1^3) - u2; (u2^3) - u1];
> u = [u1;u2];
> J = jacobian(f,u);
> Ji = inv(J);
> b = Ji*f;
> u1 = 2;
> u2 = 1;
> u = u - b
>
> my result for "u" is:
> u =
>
> u1 + (u1 - u2^3)/(9*u1^2*u2^2 - 1) + (3*u2^2*(u2 - u1^3))/(9*u1^2*u2^2 - 1)
> u2 + (u2 - u1^3)/(9*u1^2*u2^2 - 1) + (3*u1^2*(u1 - u2^3))/(9*u1^2*u2^2 - 1)
>
> I want matlab to replace all u1s with 2 and all u2s with 1. I have been searching for the past couple of hours and have not found anything. It doesn't seem like it is too hard but I just cant figure it out!
> Thanks!

I dont have the symbolic toolbox but this might work. If you can convert "u" to a character array (im not sure if that is possible at all) then you can regexprep to replace the values you want, then evaluate it with eval also, hope that helps

Subject: Change symbols back to numbers

From: John

Date: 21 Oct, 2010 22:28:03

Message: 3 of 4

"John " <jrazzano@usc.edu> wrote in message <i9qe1b$mch$1@fred.mathworks.com>...
> "Sheida " <s.d.not.this@gmail.com> wrote in message <i9q820$3h$1@fred.mathworks.com>...
> > Hi I am trying to solve an equation (to eventually put in a loop). However, after I take care of the differentiating, I cannot replace the symbols with actual numbers. Could someone please help me?
> > Here is what my m file looks like:
> > syms u1 u2
> > f = [(u1^3) - u2; (u2^3) - u1];
> > u = [u1;u2];
> > J = jacobian(f,u);
> > Ji = inv(J);
> > b = Ji*f;
> > u1 = 2;
> > u2 = 1;
> > u = u - b
> >
> > my result for "u" is:
> > u =
> >
> > u1 + (u1 - u2^3)/(9*u1^2*u2^2 - 1) + (3*u2^2*(u2 - u1^3))/(9*u1^2*u2^2 - 1)
> > u2 + (u2 - u1^3)/(9*u1^2*u2^2 - 1) + (3*u1^2*(u1 - u2^3))/(9*u1^2*u2^2 - 1)
> >
> > I want matlab to replace all u1s with 2 and all u2s with 1. I have been searching for the past couple of hours and have not found anything. It doesn't seem like it is too hard but I just cant figure it out!
> > Thanks!
>
> I dont have the symbolic toolbox but this might work. If you can convert "u" to a character array (im not sure if that is possible at all) then you can regexprep to replace the values you want, then evaluate it with eval also, hope that helps

i believe that the 'char' function will convert a sym to a string

Subject: Change symbols back to numbers

From: Roger Stafford

Date: 21 Oct, 2010 22:44:03

Message: 4 of 4

"Sheida " <s.d.not.this@gmail.com> wrote in message <i9q820$3h$1@fred.mathworks.com>...
> .......
> my result for "u" is:
> u =
>
> u1 + (u1 - u2^3)/(9*u1^2*u2^2 - 1) + (3*u2^2*(u2 - u1^3))/(9*u1^2*u2^2 - 1)
> u2 + (u2 - u1^3)/(9*u1^2*u2^2 - 1) + (3*u1^2*(u1 - u2^3))/(9*u1^2*u2^2 - 1)
>
> I want matlab to replace all u1s with 2 and all u2s with 1. I have been searching for the past couple of hours and have not found anything. It doesn't seem like it is too hard but I just cant figure it out!
> Thanks!
- - - - - - - - - - -
  Use 'subs'.

Roger Stafford

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