Why I got complex answer while I know it should be real????

조회 수: 4 (최근 30일)
Fatemeh Eslami
Fatemeh Eslami 2013년 1월 29일
Hi
I have a function to be solved. while I know it has a real answer I got complex answer, I check with 2 of my friends, one got real answer and the other one get the complex one as mine. what should I do? by the way,I want to solve it symbolic, This is the function and answer:
commands:
syms('x')
F=0.21*(exp(-0.157-0.157*x))-x
s=solve(F,x)
X=subs(s)
answer:
F = 21/(100*exp((157*x)/1000 + 157/1000)) - x
s =(1000*lambertw(0, -(100000*exp(157/1000))/3297))/157
X = 15.0552 +15.0159i
the answer tha my friend got with the same commands:
F =(21*exp(- (157*x)/1000 - 157/1000))/100 - x
s =(1000*lambertw(0, (3297*exp(-157/1000))/100000))/157
X = 0.1746

채택된 답변

owr
owr 2013년 1월 29일
My guess, and this may be a long shot, is that somewhere along the way you took the sqrt of -1.
  댓글 수: 1
Fatemeh Eslami
Fatemeh Eslami 2013년 1월 29일
thanks, but no, I dont. In fact, I have just write that one line command in my question.

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

추가 답변 (2개)

Shashank Prasanna
Shashank Prasanna 2013년 1월 29일
I got the same as your friend. Try the following
syms x F s X real
  댓글 수: 3
Fatemeh Eslami
Fatemeh Eslami 2013년 1월 29일
we both open the same mfile and run it in just separate computers.
Fatemeh Eslami
Fatemeh Eslami 2013년 1월 29일
Thanks Benji Bowbow,
this works:) syms x F s X real just I want to know that if in other cases that I am not sure about the complexity or reality of the answers,using this method gives me the correct answer or not.

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


Walter Roberson
Walter Roberson 2013년 1월 29일
Both F are the same, but your solve() is returning the wrong answer. The lambertw argument is of the form A*exp(-B) but your solve() is instead forming 1/A * exp(B) .
Which MATLAB versions are the two of you running? Is one of you running with the Maple based symbolic toolbox, and the other running with the MuPAD based symbolic toolbox?
Note: complex values are not inherently wrong solutions. The general solution is not restricted to LambertW branch 0 the way the two solutions here show.

카테고리

Help CenterFile Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by