필터 지우기
필터 지우기

solve not returning two answers

조회 수: 1 (최근 30일)
Syeda Amberin
Syeda Amberin 2019년 7월 7일
댓글: Syeda Amberin 2019년 7월 8일
Hi,
I have a nonlinear equation that I need to sovle for 'x'. Following is my code:
syms x q N
q=.95;
N=500;
eqn = 2*log((((N-x)/(q*N))^(N-x))*((x/((1-q)*N))^x)) == 3.841;
solx = solve(eqn, x);
I am expecting two values for 'x' but am getting just one (i.e. ~35). I am not getting the other value of 16. Also I get the following warning:
Warning: Cannot solve symbolically. Returning a numeric approximation instead.
Please tell me what I am doing wrong.
Thanks,

채택된 답변

infinity
infinity 2019년 7월 7일
Hello,
Maybe you could try with another approach, for example,
eq = @(y)2*log((((N-y)./(q*N)).^(N-y)).*((y./((1-q)*N)).^y)) - 3.841;
fsolve(eq,[0 100])
It will give two solutions.
ans =
16.0510 35.1056
But in this case, you should be aware that if you chose different interval of solutions, for example [-100, 100] in fsolve, you may get wrong results.
  댓글 수: 1
Syeda Amberin
Syeda Amberin 2019년 7월 8일
Thanks. This is helpful.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 7월 8일
When an equation is sufficiently complicated, solve cannot find all the exact solutions. Often it does not even know how to find one exact solution. In such cases, solve() uses vpasolve() to find one numeric solution.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 7월 8일
It is always a mistake to use solve() for equations with floating point coefficients such as 3.841. solve() is for finding exact solutions, which is something that you cannot do for equations involving inexact quantities such as 3.841. 3.841 represents a range of numbers, everything from 38405/10000 to 38149/10000. 3.841 does *not* mean 3841/1000 exactly.
Syeda Amberin
Syeda Amberin 2019년 7월 8일
Good to know. Thanks1

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by