On Wed, Mar 7, 2012 at 7:20 PM, Irucka Embry <[email protected]> wrote:
> Hi William, thanks again for your clarification and assistance.
>
> Is there any way to get a numerical approximation when using the solve
> function, such as in the two examples below?
>
> 1) var('x, y')
> solve([160000*x+40000*y-1600*x+5*x==5, 160000*y-40000*x-1600*y+5*y==0], x,
> y)
> [[x == (31681/1067685761), y == (8000/1067685761)]]

Here's some relevant sage:

sage: s = solve([160000*x+40000*y-1600*x+5*x==5,
160000*y-40000*x-1600*y+5*y==0], x, y, soln_dict=true)
sage: s
[[x == (31681/1067685761), y == (8000/1067685761)]]
sage: s = solve([160000*x+40000*y-1600*x+5*x==5,
160000*y-40000*x-1600*y+5*y==0], x, y, solution_dict=true)
sage: s
[{y: 8000/1067685761, x: 31681/1067685761}]
sage: s = solve([160000*x+40000*y-1600*x+5*x==5,
160000*y-40000*x-1600*y+5*y==0], x, y, solution_dict=true)
sage: s = solve([160000*x+40000*y-1600*x+5*x==5,
160000*y-40000*x-1600*y+5*y==0], x, y, solution_dict=true)[0]
sage: s
{y: 8000/1067685761, x: 31681/1067685761}
sage: s[x].N()
0.0000296725882813380
sage: s[y].N()
7.49284133236652e-6
sage: s[y].N(200)
7.4928413323665182793423054744662835304029122478856398273162e-6
sage: s[x].N(200)
0.000029672588281337958200980447467070791065836832865658119421151

>
> 2) y = var('y')
> u = 4.8;
> H = 220;
> sigmay = 154.09;
> sigmaz = 109.30;
> C1 =
> (solve([(900000000/(pi*u*sigmay*sigmaz))*((exp((-H^2)/(2*sigmaz^2))))*((exp((y^2)/(2*sigmay^2))))
> == 50], y))
>
> [y ==
> -sqrt(2184423)*sqrt(log(1/236419*pi^(1/46)*5^(1/23)*322^(1/46)*236419^(4\
> 5/46)*e^(1/23*I*pi))), y ==
> sqrt(2184423)*sqrt(log(1/236419*pi^(1/46)*5^(1/23)*322^(1/46)*236419^(45\
> /46)*e^(1/23*I*pi))), y ==
> -sqrt(2184423)*sqrt(log(1/236419*pi^(1/46)*5^(1/23)*322^(1/46)*236419^(4\
> 5/46)*e^(2/23*I*pi))), y ==
> sqrt(2184423)*sqrt(log(1/236419*pi^(1/46)*5^(1/23)*322^(1/46)*236419^(45\
> /46)*e^(2/23*I*pi))), y ==
> -sqrt(2184423)*sqrt(log(1/236419*pi^(1/46)*5^(1/23)*322^(1/46)*236419^(4\
> 5/46)*e^(3/23*I*pi))), ...]
>
>
> Thanks again.
>
> Mr. Irucka Embry
>
>
>
> <-----Original Message----->
>>From: William Stein [[email protected]]
>>Sent: 3/5/2012 9:24:42 AM
>>To: [email protected]
>>Cc: [email protected]
>>Subject: Re: [sage-support] Re: GNU Octave and Sage?
>>
>>On Mon, Mar 5, 2012 at 7:17 AM, P Purkayastha <[email protected]> wrote:
>>>
>>>
>>> On Monday, March 5, 2012 9:22:14 PM UTC+8, William wrote:
>>>>
>>>>
>>>>
>>>> On Sunday, March 4, 2012, Irucka Embry <[email protected]>
>>wrote:
>>>>
>>>> > It would be very helpful to have an option to have a decimal
>>answer when
>>>> > performing calculations, especially when solving complex linear and/or
>>>> > nonlinear equations, such as is possible with Matlab, GNU Octave,
>>Scilab,
>>>> > etc. It is very difficult to find any answers online, in the Sage
>>search
>>>> > engine, etc. to that question.
>>>> >
>>>>
>>>> Sage output is always displayed in decimal by default, so I do not
>>>> understand your question at all.
>>>
>>>
>>> I think what (s)he meant is that by default stuff is not printed in
>>> decimals, example:
>>>
>>> sage: log(3,2)
>>> log(3)/log(2)
>>>
>>> To the OP:
>>> To get the numerical result at the end, simply use .n() like:
>>>
>>> sage: log(3,2).n()
>>> 1.58496250072116
>>>
>>> This is very useful since Sage can do exact computations, and does so by
>>> default (always?). There are some inherent precision problems if you use
>>> Matlab or Octave and you want accurate results
>>
>>
>>If you have an expression in Sage and want to get it in decimal where
>>every digit it prints (except the last) is *definitely* correct, use
>>RIF(...). For example,
>>
>>sage: RIF(log(3,2))
>>1.584962500721156?
>>
>>If you don't care -- and just want something quick, use
>>numerical_approx (same as .n() suggested above):
>>
>>sage: a = sin((1e10+1e-10)*pi)
>>sage: a
>>sin(1.00000000000000e10*pi)
>>sage: numerical_approx(a) # don't care -- not so good since all
>>printed digits wrong
>>-2.23936276195592e-6
>>sage: RIF(a) # every displayed digit (except
>>possibly the last) is guaranteed correct
>>0.00000?
>>sage: RealIntervalField(200)(a) # get up to 200 bits correct
>>0.?e-49
>>
>> -- William
>>.
>>
>
> _______________________________________________________________
> Get the Free email that has everyone talking at http://www.mail2world.com
> Unlimited Email Storage – POP3 – Calendar – SMS – Translator – Much More!



-- 
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to