Nonlinear equation returning Empty sym: 0-by-1

syms B R
eqn1 = B/Jeq + R/La == 183.9;
eqn2 = (Ka*Ke + R*B)/(Jeq*La) == 4505;
eqn3 = B > 0;
eqn4 = R > 0;
[B1,R1] = solve([eqn1,eqn2,eqn3,eqn4],[B,R])
%Then it returns:
%B1 =
%Empty sum: 0-by-1
%R1 =
%Empty sum: 0-by-1
Edit: My equations are unable to be solved with those constraints because my initial equations are wrong. However, with Walter Roberson's solutions in this thread, I would now be able to solve it otherwise.

 Accepted Answer

The solutions could potentially be more constrained if we knew that Jeq and La were both positive: in that case it would be known that the second solution would be negative or imaginary.
If I have followed correctly, there are potentially solutions if Jeq is negative but La is positive; I might have missed something though.
syms Jeq Ka Ke La
syms B R positive
eqn1 = B/Jeq + R/La == 183.9;
eqn2 = (Ka*Ke + R*B)/(Jeq*La) == 4505;
sol = solve([eqn1,eqn2],[B,R], 'returnconditions', true)
sol = struct with fields:
B: [2×1 sym] R: [2×1 sym] parameters: [1×0 sym] conditions: [2×1 sym]
sol.B
ans = 
sol.R
ans = 
sol.conditions
ans = 

4 Comments

Hi Walter,
Thank you for the unbelievably quick response! I was wondering whether not I would get one, let alone in less than an hour.
As per my question, Jeq, Ka, Ke and La are all positive constants. I put in the constant values to see if I could get it to work and it still wouldn't. Not sure why the code below didnt work, when yours did. Does adding the second syms function do something? Also regarding the answers your code outputed, how do I interpret that? Why is there a column of 2 numbers for only 1 variable?
This is what I tried:
syms B R positive
eqn1 = B/(3*10^(-5)) + R/(10^(-3)) == 183.9;
eqn2 = (0.040^2 + R*B)/(((3*10^(-5))*10^(-3))) == 4505;
sol = solve([eqn1,eqn2],[B,R], 'returnconditions', true)
sol.B
sol.R
Update: I used this code instead and it did work and I got it to output numerical values for me. However, in the outputs, each one has a negative value in each column. Still not sure how to read that output matrix , but R and B must be positive. Rremoving the 'positive' in the first line made it output numbers somehow:
Working code with a negative value in the B and R columns:
syms B R
eqn1 = B/(3*10^(-5)) + R/(10^(-3)) == 183.9;
eqn2 = (0.040^2 + R*B)/(((3*10^(-5))*10^(-3))) == 4505;
sol = solve([eqn1,eqn2],[B,R], 'returnconditions', true)
sol.B
var = vpa(ans)
sol.R
var2 = vpa(ans)
Just tried a different way to ensure B and R are postivie and it didn't work:
syms B R
eqn1 = B/(3*10^(-5)) + R/(10^(-3)) == 183.9;
eqn2 = (0.040^2 + R*B)/(((3*10^(-5))*10^(-3))) == 4505;
eqn3 = B>0;
eqn4 = R>0;
sol = solve([eqn1,eqn2,eqn3,eqn4],[B,R], 'returnconditions', true)
sol.B
var = vpa(ans)
sol.R
var2 = vpa(ans)
With those particular values, B and R cannot both be positive. One can be positive but the other has to be negative.
Q = @(v) sym(v);
syms Jeq Ka Ke La positive
Jeq_val = Q(3e-5)
Jeq_val = 
Ka_val = Q(0.040)
Ka_val = 
Ke_val = Q(0.040)
Ke_val = 
La_val = Q(1e-3)
La_val = 
syms B R positive
eqn1 = B/Jeq + R/La == 183.9;
eqn2 = (Ka*Ke + R*B)/(Jeq*La) == 4505;
sol = solve([eqn1,eqn2],[B,R], 'returnconditions', true)
sol = struct with fields:
B: [2×1 sym] R: [2×1 sym] parameters: [1×0 sym] conditions: [2×1 sym]
sol.B
ans = 
sol.R
ans = 
sol.conditions
ans = 
subs(sol.conditions, {Jeq, Ka, Ke, La}, {Jeq_val, Ka_val, Ke_val, La_val})
ans = 
simplify(ans)
ans = 
subs(sol.B, {Jeq, Ka, Ke, La}, {Jeq_val, Ka_val, Ke_val, La_val})
ans = 
simplify(ans)
ans = 
vpa(ans)
ans = 
subs(sol.R, {Jeq, Ka, Ke, La}, {Jeq_val, Ka_val, Ke_val, La_val})
ans = 
simplify(ans)
ans = 
vpa(ans)
ans = 
Ah ok thank you! I must've messed up somewhere earlier on when making my equations. Thanks so much for your help, very appriciated!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!