Solver Equation not giving solution
이전 댓글 표시
I want to know the x value of this equation but is giving error i did this:
>> syms x k px
>> eq1 = k == 0.04;
>> eq2 = px ==3.5;
>> eq3 = k== (x./1-x)*sqrt((2*px)./(2+x));
>> sol = solve([eq1,eq2,eq3],[x,k,px]);
>> xsol = sol.x
xsol =
Empty sym: 0-by-1
>>
답변 (1개)
David Goodmanson
2020년 5월 22일
Hi Diogo,
Matlab syms can solve this, but it needs some help, which is squaring both sides of eqn3 to form a new eqn3. Also since k and px have numeric values there is no need to declare them as syms. An economy sized version of the code is
syms x
k = .04;
px = 3.5;
% eq3 = k == (x./1-x)*sqrt((2*px)./(2+x));
eq3 = k^2 == (x./(1-x)).^2.*(2*px)./(2+x);
sol = solve(eq3,x)
sol =
root(z^3 - 4375*z^2 - 3*z + 2, z, 1)
root(z^3 - 4375*z^2 - 3*z + 2, z, 2)
root(z^3 - 4375*z^2 - 3*z + 2, z, 3)
vpa(sol,10)
ans =
0.02104084079
-0.02172645048
4375.000686
All three roots work for the squared eq3 but it's necessary to go back to the original eq3 and see how many solutions there are. It turns out that the first listed root above works if you take the positive square root in eq3 and the second two listed roots work for the negative square root in eq3.
카테고리
도움말 센터 및 File Exchange에서 Equation Solving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!