On Thu, Oct 2, 2008 at 6:43 PM, William Stein <[EMAIL PROTECTED]> wrote:
>
> On Thu, Oct 2, 2008 at 9:31 AM, jdmuys <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> I am a total newcomer, and here is very simple high-school level
>> question for which I could not find an answer in several hours of
>> searching:
>>
>> How can I use Sage to simplify ratios involving complex numbers?
>>
>> By simplify, I mean, to put into the canonical form a+b*i.
>>
>> For a very simple example: simplifying x=1/(1+i) would yield (1/2 - i/
>> 2)
>>
>> Note: this is simple to do by hand: multiply both numerator and
>> denominator by the conjugate of the denominator. For my example, this
>> leads to:
>>
>> x= (1-i)/[(1+i)(1-i)]
>> x = (1-i)/[1^2-i^2]
>> x = (1-i)/[1+1]
>> x = (1-i)/2
>> x = 1/2 -i/2
>>
>> I tried quite a number of things, none of which worked.
>>
>> Thanks, and sorry if my question is easy (well actually, I hope it's
>> easy ;-)
>>
>
> You could get the real and imaginary parts, as follows:
>
> sage: a = (1-I)/(1 + I)
> sage: a.real() + I*a.imag()
> -1*I
>
> If you're coefficients are all rational numbers, you could
> alternatively define I to be the generator for the "ring" QQ[sqrt(-1)],
> as follows, and all such expressions will automatically
> be simplified the moment you type them in:
>
> sage: I = QQ[sqrt(-1)].gen()
> sage: 1/1 + I
> I + 1
> sage: 1/(1 + I)
> -1/2*I + 1/2
> sage: (1-I)/(1 + I)
> -I
>
> Note that expressions like sqrt(2)*I will no longer work
> with this new version of I.  To get back the old I, you
> can do
> sage: reset('I')

Or through some package, e.g. sometimes sympy's simplification works well:

sage: a = (1-I)/(1 + I)
sage: import sympy
sysage: sympy.simplify(a)
-I
sage: SR(sympy.simplify(a))
-1*I

The SR() converts the expression back from a sympy expression to a
Sage expression.

Ondrej

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to