Got this ''Empty sym: 0-by-1''
조회 수: 429 (최근 30일)
이전 댓글 표시
This is a simplified version of a code I'm doing for my school assignment. I don't know why the answer always come out as Empty sym: 0-by-1. I already tried many ways.
Thank you in advance.
syms x;
q = 1:3;
w = 2;
eqn = (3*x) + q + w == 0;
sol = solve(eqn);
vpa(sol)
댓글 수: 0
답변 (4개)
Walter Roberson
2023년 1월 13일
solve() is for solving simultaneous equations. for example asking to solve [x+y==9,x-y==4] does not output a set of solutions for x+y==9 and a set of solutions for x-y==4: it finds the solution for both equations considered together.
You are passing a vector of three equations to solve() and asking for the set of values such that all of the equations are satisfied with the same value. There is no such value.
If you want to solve each equation separately you need multiple calls to solve. For example arrayfun(@solve, eqn)
댓글 수: 0
Luca Ferro
2023년 1월 13일
solve returns 'Empty sym: 0-by-1' when there is no explicit solution to the equation.
The equation has no solution because of the assignment q=1:3;
when you use an array like that in the line where the equation is defined it defines it as:
[3*x + 3 == 0, 3*x + 4 == 0, 3*x + 5 == 0]
Clearly the above cited set of equations has no solution.
It's not clear what you want to achieve with q=1:3; , so i can't give you an alternative solution to the code you have written.
If you could specify what you goal was we can figure something out, otherwise now that you know the issue you can solve it by yourself.
댓글 수: 0
John D'Errico
2023년 1월 13일
편집: John D'Errico
2023년 1월 13일
I'll suggest you did things in the wrong order.
syms x
syms q % leave q as an unknown parameter for the moment.
w = 2;
eqn = (3*x) + q + w == 0;
xsol = solve(eqn,x)
Here, we see that x is a function of the unknown parameter q. Only NOW at the very end do we substitute the possible values of q.
subs(xsol,q,1:3)
Your problem was you defined q in advance as a vector, and that confused MATLAB. It tried to then define 3 equations, but with only the one unknown x, and that must fail.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!