# Error in solve (line 226)

16 views (last 30 days)
Huda Alzaki on 27 Sep 2019
Commented: Walter Roberson on 7 Mar 2021
I always get an error while trying to solve even simple equation. I have this code:
clc, clear
syms N
N= 10;
y = 1/N^2;
and I got this error:
Error using solve (line 266)
Specify the variable to solve for.
Error in Untitled5 (line 5)
##### 3 CommentsShow 1 older commentHide 1 older comment
venkat reddy on 7 Mar 2021
how to solve this
Walter Roberson on 7 Mar 2021
use the debugger
dbstop if error
and run the code. When it stops, show us the line of code that it is saying is the problem, and the error message, and the size() and class() of all the variables mentioned on the line.

Walter Roberson on 28 Sep 2019
subs(y, N, 10)
without having assigned 10 to the symbolic variable N.
If you have gone ahead and assigned a numeric value to what was previously a symbolic variable (not recommended!) then you can use either
subs(y, sym('N'), N)
or
subs(y)
The first of those would substitute only for the variable N, but the second would substitute for any variable in y that has been given a value.

Katarina Vuckovic on 27 Sep 2019
You are setting the "unknown" value to be N in the first line and then you are setting N =10 in teh second line. If you want to solve for y, you should set your "unknown" to be y.
Options to fix the code:
1) If you just want to find the value of y, you don't need to use the "solve" function. Just say
y = 1/N^2
2) If you want to use the "solve" function, you can do something like y = 1/N^2 therefore N = 1/sqrt(y) so now you have 10=1/sqrt(y):
syms y
y = 10
eqn = 1/sqrt(y) == 10;
S = solve(eqn,y)
Walter Roberson on 28 Sep 2019
syms y
y = 10
The y = 10 there overrides the syms y and would give the same problem as the original poster. That y = 10 should be removed.

Steven Lord on 27 Sep 2019
In your code, you first defined N to be a symbolic variable using syms. However, on the very next line you redefined it to be the number 10. This makes y (which you compute using N) a number rather than a symbolic expression. Since the number you pass into solve doesn't contain a symbolic variable, solve doesn't know what you want it to do.
I'm not completely sure what problem you're trying to solve, but leaving N as a symbolic variable (eliminating the line that redefines it to be 10) before calling solve then using subs to substitute a value back for N after solving may do what you want. If it doesn't, please explain in more detail your ultimate goal and we may be able to offer some suggestions for how to achieve that goal.

Huda Alzaki on 28 Sep 2019
Actully I have this expression (y = 1/N^2) and I want to get the value of y for N = 10. Sometimes, i have long algebric expressions and I want to get the value of y for multible values of N.

Katarina Vuckovic on 30 Sep 2019
Edited: Katarina Vuckovic on 30 Sep 2019
N = 10 -> here is where you change the value of N
y = 1/(N*N)