필터 지우기
필터 지우기

Solve fails to find a solution for trivial linear system

조회 수: 1 (최근 30일)
Daniel
Daniel 2016년 3월 5일
댓글: Walter Roberson 2016년 3월 6일
I'm trying to find the value of G in the following set of equations by code:
clear all; clc;
syms R T S u yr y B A G
eq1 = R*u == T*yr - S*y;
eq2 = y == (B/A)*u;
eq3 = y == G*yr;
solve([eq1,eq2,eq3], G)
However, solve fails with an empty solution set, although this system has a trivial answer.
It's easy to see how it can be done, from eq1:
u == (T*yr - S*y)/R
From eq2:
y == (B/A)*(T*yr - S*y)/R
Thus:
y = yr*(B*T)/(A*R + B*S)
Finally, from eq3:
G = (B*T)/(A*R + B*S)
I can't understand why solve fails in this case. I appreciate any help I can get.

채택된 답변

Walter Roberson
Walter Roberson 2016년 3월 6일
Actually it is just a matter of telling it all three variables to solve for:
solve(eq1, eq2, eq3, y, u, G)
  댓글 수: 2
Daniel
Daniel 2016년 3월 6일
편집: Daniel 2016년 3월 6일
Wow, that was exactly it! Is there a specific reason why I need two more variables?
I used:
res = solve([eq1,eq2,eq3], [y,u,G])
and it worked perfectly. Thank you, Walter!
Walter Roberson
Walter Roberson 2016년 3월 6일
When you do not specify the other variables, the best you could have hoped for was that G was returned as y/yr, from the third equation, as it would have had no reason to know which other variables to eliminate.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Star Strider
Star Strider 2016년 3월 6일
Sometimes, you have to lead it gently by the hand:
syms R T S u yr y B A G
eq1 = R*u == T*yr - S*y;
eq2 = y == (B/A)*u;
eq3 = y == G*yr;
eq4 = solve(eq2, eq3);
yr = eq4.yr;
eq5 = subs(eq1, yr);
G_solved = solve(eq5, G)
G_solved =
-(B*S*u)/(A*(R*u - T*yr))
  댓글 수: 1
Daniel
Daniel 2016년 3월 6일
Star, as always, great answer and you're one of the most helpful people here but I'll have to hand this one to Walter Roberson because he hit the nail on the head. Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by