MATLAB Answers

symbolic system of equations matlab

30 views (last 30 days)
Abidi Aymen
Abidi Aymen on 11 Jan 2021
Edited: Walter Roberson on 12 Jan 2021
Hello,
I need help with this task!
I did not get a solution to system 1. All i had: Empty sym: 0-by-1
But when i assign values to X,Y and Z (like in 2) it works. I need a symbolic solution as a function of X,Y and Z.
**************************1********************************
syms X Y Z Theta1 Theta2 Theta3
F = zeros(3,1);
eqn1 = F(1) == (cos(Theta2)+cos(Theta3-Theta2))*sin(-Theta1) - X;
eqn2 = F(2)== (cos(Theta2)+cos(Theta3-Theta2))*cos(Theta1) -Y;
eqn3 = F(3)== 1+sin(-Theta2)+sin(Theta3-Theta2)-Z;
[Theta1,Theta2,Theta3] = solve(eqn1,eqn2,eqn3,Theta1,Theta2,Theta3);
**************************2********************************
syms X Y Z Theta1 Theta2 Theta3
F = zeros(3,1);
eqn1 = F(1) == (cos(Theta2)+cos(Theta3-Theta2))*sin(-Theta1) - 0;
eqn2 = F(2)== (cos(Theta2)+cos(Theta3-Theta2))*cos(Theta1) -0;
eqn3 = F(3)== 1+sin(-Theta2)+sin(Theta3-Theta2)-3;
[Theta1,Theta2,Theta3] = solve(eqn1,eqn2,eqn3,Theta1,Theta2,Theta3);

  0 Comments

Sign in to comment.

Answers (2)

Doddy Kastanya
Doddy Kastanya on 12 Jan 2021
You might want to check out the information in the following link https://www.mathworks.com/help/symbolic/solve-a-system-of-algebraic-equations.html .

  1 Comment

Walter Roberson
Walter Roberson on 12 Jan 2021
these are not algebraic equations.

Sign in to comment.


Walter Roberson
Walter Roberson on 12 Jan 2021
Edited: Walter Roberson on 12 Jan 2021
syms X Y Z Theta1 Theta2 Theta3
F = zeros(3,1);
eqn1 = F(1) == (cos(Theta2)+cos(Theta3-Theta2))*sin(-Theta1) - X;
eqn2 = F(2)== (cos(Theta2)+cos(Theta3-Theta2))*cos(Theta1) -Y;
eqn3 = F(3)== 1+sin(-Theta2)+sin(Theta3-Theta2)-Z;
E = [eqn1, eqn2, eqn3];
vars = [Theta1,Theta2,Theta3]
vars = 
sol1 = solve(E(1), vars(1))
sol1 = 
E2 = simplify( rewrite(subs(E(2:end), vars(1), sol1(1)), 'sinhcosh'),'steps', 50)
E2 = 
sol3 = solve(E2(2), vars(2))
sol3 = 
E3 = simplify(rewrite(subs(E2([1 3:end]), vars(2), sol3(1)),'sinhcosh'),'steps',1)
E3 = 
sol2 = solve(E3(1), vars(3), 'returnconditions', true)
sol2 = struct with fields:
Theta3: [1×1 sym] parameters: [1×1 sym] conditions: [1×1 sym]
sol2.Theta3
ans = 
z
sol2.conditions
ans = 
cs = simplify(sol2.conditions, 'steps', 25)
cs = 
And then start analyzing sol2.conditions .
You can potentially get further by assuming that X, Y, and Z are real-valued.
cc = children(cs);
eqz = simplify(lhs(cc{1})-rhs(cc{1}), 'steps', 10)
eqz = 
z1 = solve(eqz, Z, 'returnconditions', true)
z1 = struct with fields:
Z: [0×1 sym] parameters: [1×0 sym] conditions: [0×1 sym]
That is empty.. does that mean that the two can never be equal and so the first condition is always true?
Xtry = randi([-9 9])
Xtry = 7
Ytry = randi([-9 9])
Ytry = 5
eqtry = simplify(subs(eqz, {X, Y}, {Xtry, Ytry}), 'steps', 10)
eqtry = 
solve(eqtry, Z, 'returnconditions', true)
ans = struct with fields:
Z: [0×1 sym] parameters: [1×0 sym] conditions: [0×1 sym]
fplot(eqtry, [-10 10])
limit(eqtry, Z, inf)
ans = 
0
So there would seem to be equality at infinity, which implies inequality otherwise, which implies the first condition does hold. But what about 0 ?
eqtry = simplify(subs(eqz, {X, Y}, {0, 0}), 'steps', 10)
eqtry = 
solve(eqtry, Z, 'returnconditions', true)
ans = struct with fields:
Z: [0×1 sym] parameters: [1×0 sym] conditions: [0×1 sym]
fplot(eqtry, [-10 10])
fplot(imag(eqtry), [-1 1])
fplot(imag(eqtry), [1 3])
Nope, those generate complex values in part of the range, but never equal 0
subs(eqtry, Z, 1)
ans = 
The imaginary part of that is 0, and the real part is negative whereas the real part of the previous eqtry plots were positive, but there is no zero crossing over real-valued Z. It might be worth investigating more to determine if there is an imaginary Z.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by