The expression to the left of the equals sign is not a valid target for an assignment
조회 수: 4 (최근 30일)
이전 댓글 표시
both x and y has been introduced by syms. This seems to me perfectly correct. What is wrong here?
>> solve(5*x + 4*y = 3, x-6*y = 2)
solve(5*x + 4*y = 3, x-6*y = 2)
↑
Error: The expression to the left of the equals sign is not a valid target for an assignment.
Then I tried this
>> solve('5*x + 4*y = 3, x-6*y = 2')
Warning: Support of character vectors will be removed in a future release. Character vectors can be used only for variable names and
numbers. Instead, to create symbolic expressions first create symbolic variables using 'syms'. To evaluate character vectors and
strings representing symbolic expressions, use 'str2sym'.
> In sym>convertExpression (line 1581)
In sym>convertChar (line 1486)
In sym>tomupad (line 1236)
In sym (line 215)
In solve>getEqns (line 406)
In solve (line 226)
Warning: Do not specify equations and variables as character vectors. Instead, create symbolic variables with syms.
> In solve>getEqns (line 446)
In solve (line 226)
ans =
struct with fields:
x: [1×1 sym]
y: [1×1 sym]
It says something about x and y. Would you please explain the situation in a simple way?
Thank you.
댓글 수: 0
채택된 답변
Walter Roberson
2020년 11월 8일
편집: Walter Roberson
2020년 11월 8일
syms x y
sol = solve(5*x + 4*y == 3, x-6*y == 2);
pretty(sol.x), pretty(sol.y)
댓글 수: 2
Walter Roberson
2020년 11월 8일
You used
solve(5*x + 4*y = 3, x-6*y = 2)
but = is the assignment operator, not the comparison operator.
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!