The expression to the left of the equals sign is not a valid target for an assignment

9 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Nov 2020
Edited: Walter Roberson on 8 Nov 2020
syms x y
sol = solve(5*x + 4*y == 3, x-6*y == 2);
pretty(sol.x), pretty(sol.y)
13 -- 17 7 - -- 34
  2 Comments
metin yilmaz
metin yilmaz on 8 Nov 2020
Would you please explain what was wrong with my attempt? what does
ans =
struct with fields:
x: [1×1 sym]
y: [1×1 sym]
mean?
Thank you.

Sign in to comment.

More Answers (1)

metin yilmaz
metin yilmaz on 8 Nov 2020
Edited: metin yilmaz on 8 Nov 2020
The reference is quite difficult for me to understand. I am someone with no background of data structures. Would you please explain it to me over this simple example?
>> solve(5*x + 4*y == 3, x-6*y == 2)
ans =
struct with fields:
x: [1×1 sym]
y: [1×1 sym]
2. But when I did s.x it gave me this notification. non-existent field.
solve(5*x + 4*y == 3, x-6*y == 2) ;s.x
Reference to non-existent field 'x'.
b=solve(5*x + 4*y == 3, x-6*y == 2)
b =
struct with fields:
x: [1×1 sym]
y: [1×1 sym]
>> b.x
ans =
13/17
>> b.y
ans =
-7/343. b=solve(5*x + 4*y == 3, x-6*y == 2)
b =
struct with fields:
x: [1×1 sym]
y: [1×1 sym]
>> b.x
ans =
13/17
>> b.y
ans =
-7/34

Community Treasure Hunt

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

Start Hunting!