student1
student1

Reputation: 879

symbolic substitution in Matlab

The function subs in matlab does not work as expected with me. I define a symbolic variable, then assign it a value of 0, but later I discover it has not been assigned anything.

syms x1
a=x1
subs(a,x1,0)
a

produces

x1

and not 0. Any ideas?

Upvotes: 1

Views: 988

Answers (1)

Dan
Dan

Reputation: 10786

From my documentation for MATLAB:

subs(s,old,new) returns a copy of s replacing all occurrences of old with new, and then evaluating s.

subs doesn't modify a, it returns a modified version of it. For example, try this:

syms x1;
a = x1;
b = subs(a,x1,0);
a
b

Returns

a = x1
b = 0

Upvotes: 2

Related Questions