سؤال

I've tried:

>> dsolve('Dy=(x+2)/(x*(3-x))','y(1)=2','x')

And got this answer:

ans = (pi*5*i)/3 - (5*log(x - 3))/3 + (5*log(2))/3 + (2*log(x))/3 + 2

The correct hand generated answer is:

y = 2/3*log(x) -5/3*log(3-x) + (2+5/3*log(2))

How do I eliminate the complex number in the Matlab answer?

OK, tried this:

>> dsolve(diff(y)==(x+2)/(x*(3-x)),y(1)==2,x)

ans =

(pi*5*i)/3 - (5*log(x - 3))/3 + (5*log(2))/3 + (2*log(x))/3 + 2

>> real(ans)

ans =

(2*log(abs(x)))/3 + (5*log(2))/3 - (5*log(abs(x - 3)))/3 + 2

>> pretty(ans)

  2 log(|x|)   5 log(2)   5 log(|x - 3|)
  ---------- + -------- - -------------- + 2
      3           3             3
هل كانت مفيدة؟

المحلول

If your use of matlab gives one answer and your manual labor gives another, don't be too quick to assume that matlab iis at fault.

That being said, getting the real part of a number is very easy, I can't try it but with the symbolic toolbox I believe you can just do:

real(y)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top