Substituting a variable in an equation
Show older comments
Hi,
I have a set of equations in which certain variable and values are to be substituted. But when I use the subs function, it doesn't seem to work.
syms r Y L0 L1 L2 p1 p2 x y
eqn1 = L0+L1*cos(x)+p2*cos(x+y) == r*sin(x+y);
eqn2 = L1*sin(x)+p2*sin(x+y) == Y-r*cos(x+y);
Now, x and y are given by another set of equations
x = acos((r^2-p1^2)/(r^2+p1^2));
y = acos((r^2-p2^2)/(r^2+p2^2));
I also have other set of equations for my dependent variables.
Y = r;
p1 = L0;
p2 = L1 - L0;
I need to substitute these values back into my equations and so I use subs function and it works as expected.
eqn3 = subs(eqn1);
eqn4 = subs(eqn2);
But the problem is, I need to simplify my main equations with x+y = pi/2. This is just one case and the value will change for other cases, so I can't simplify my main equations directly. I use subs function once again for this substitution process.
eqn1=subs(eqn1,x+y,pi/2);
eqn2=subs(eqn2,x+y,pi/2);
Since, the subs function replaces x and y with their corresponding equations, it is pointless to use it here, so I am using the last set of subs function before my x and y substitution and my final code looks like as below.
syms r Y L0 L1 L2 p1 p2 x y
eqn1 = L0+L1*cos(x)+p2*cos(x+y) == r*sin(x+y);
eqn2 = L1*sin(x)+p2*sin(x+y) == Y-r*cos(x+y);
x = acos((r^2-p1^2)/(r^2+p1^2));
y = acos((r^2-p2^2)/(r^2+p2^2));
Y = r;
p1 = L0;
p2 = L1 - L0;
eqn1=subs(eqn1,x+y,pi/2);
eqn2=subs(eqn2,x+y,pi/2);
eqn3 = subs(eqn1);
eqn4 = subs(eqn2);
But still, the x+y simplification doesn't seem to work and the entire equation is substituted with the values of x and y. How do I fix this?
Thanks,
Abinav
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!