ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 10 Nov 2020 19:48:58 -0600plot does not gibe with solve for log equationshttps://ask.sagemath.org/question/54209/plot-does-not-gibe-with-solve-for-log-equations/ If I plot two log equations in x and y I get an obvious intersection, but when I try solve on them I get nothing. Is there a way to get a mathematical solution that gibes with the plot?
var('x y')
implicit_plot(log(x*sqrt(y)),(x,0,8),(y,0,8),color="black") + implicit_plot(log(x^2*y^2),(x,0,8),(y,0,8),color="red")
solve(log(x*sqrt(y)) == log(x^2*y^2),x,y)
[]
![image description](/upfiles/16050592939713841.png)cybervigilanteTue, 10 Nov 2020 19:48:58 -0600https://ask.sagemath.org/question/54209/log(e) won't convert to 1https://ask.sagemath.org/question/53601/loge-wont-convert-to-1/Is there a way to make log(e) print as 1? I know they're equal but I can't get sage to do that, and in complex expressions it's tedious to redo all the log(e)s.
f(x) = e^x*cos(x)
f_int(x) = integrate(f,x)
f_int(x)
result
(e^x*cos(x)*log(e) + e^x*sin(x))/(log(e)^2 + 1)
cybervigilanteFri, 25 Sep 2020 18:18:11 -0500https://ask.sagemath.org/question/53601/Behavior of numerical_approx functionhttps://ask.sagemath.org/question/41343/behavior-of-numerical_approx-function/What I noticed is that the `log` function does not give a numerical approximation by default, and one has to use the `numerical_approx` (`n`) function for this purpose. Though, I found its behavior a bit interesting, or not what I expected. I have a Sage code that looks like this:
p = 2**372 * 3**239 - 1
log(p, 2).numerical_approx() # 750.806037672356
log(p, 2).numerical_approx(digits = 4) # 750.8
log(p, 2).numerical_approx(digits = 7) # 750.8060
So, by default `numerical_approx` gives 12 digits after the decimal point, but I found that it optionally takes an argument called `digits`. The confusing part for me is that I thought that `digits` specifies how many digits to be displayed after the decimal point, but this clearly is not the case, as you can see from the examples above. It actually specifies how many digits in total (sum of digits before and after the decimal point) it should print. So, how can I get numerical approximation of logarithms with 4 digits after the decimal point (no matter how many digits there are before the decimal point)?ninhoThu, 01 Mar 2018 14:38:58 -0600https://ask.sagemath.org/question/41343/Why can Sage solve one log equation, but not another with only different values?https://ask.sagemath.org/question/26237/why-can-sage-solve-one-log-equation-but-not-another-with-only-different-values/ solve(3 == 586 * 0.2 ^ x, x)
[x == log(586/3)/log(5)] // Numerical: 3.27736003989833
solve(3 == 586 * 0.99557 ^ x, x)
[100000^x == 586/3*99557^x] // Wat???
Why is it not capable of solving the second equation?
Math tells us there is a solution and that it is:
log(3/586) / log(0.99557) = 1188.03958878842WoodgnomeWed, 18 Mar 2015 04:00:47 -0500https://ask.sagemath.org/question/26237/log-normal and gaussian distribution - array generationhttps://ask.sagemath.org/question/10683/log-normal-and-gaussian-distribution-array-generation/Hi experts!
I wanna generate a random number array of size=`N` using a log normal distribution. From `http://en.wikipedia.org/wiki/Log-normal_distribution` i wanna use the parameters `mu` and `sigma`.
I know that I must do:
form scipy.stats import lognorm
new_array = lognorm.rvs(......, size=N)
What must I set like parameters (loc, s, scale, etc.) for use mu and sigma distribution parameters.
In the same way: what must I do in
new_array = norm.rvs(......, size=N)
for generate a array of random numbers using a gaussian distribution with parameters `mu` and `sigma`?
Waitign for your answers.
Thanks a lot!mresimulatorFri, 01 Nov 2013 05:19:36 -0500https://ask.sagemath.org/question/10683/A log(101,base=10) that doesn't reply log(101)/log(10)https://ask.sagemath.org/question/10655/a-log101base10-that-doesnt-reply-log101log10/How can we develop the function below ?
Where should we start to read?
"""
HSLOG = "High School Log".
Treat forms like `\log_b(a^p)` in a special manner.
Standard sage log with integer arguments works like this:
::
sage: log(101^3,10)
log(1030301)/log(10)
sage: 3*log(101,10)
3*log(101,10)
sage: 10^log(101,base=10) #101
10^(log(101)/log(10))
and
::
sage: log(101,10)
log(101)/log(10)
sage: latex( log(101,10) )
\frac{\log\left(101\right)}{\log\left(10\right)} %ie: log(101)/log(10)
What we want is:
sage: HSLOG(101,10,3) #log_{10}(101^3)
3*log(101,10)
sage: HSLOG(101,10) #log_{10}(101)
log(101,10)
sage: 10^HSLOG(101,10) #10^log_{10}(101^3) = 101
101
sage: latex( HSLOG(101,10) )
\log_{10}(101)
"""PedroFri, 25 Oct 2013 06:00:47 -0500https://ask.sagemath.org/question/10655/Solid lines in plot and grid lineshttps://ask.sagemath.org/question/9244/solid-lines-in-plot-and-grid-lines/I have a plot which sweeps over a range shown below and the plots it on a log scale on the horizontal axis (I am using 5.2 so the log scale feature is present).
1. However, rather than points, I would like to see a solid line and,
2. Some grid lines on both the horizontal and vertical axis at the tick points.
3. Is there also a way to control the range on the vertical axis?
Here is the entire formulation. The range on the y-axis I would like to see labeled is from -5 to -25. I asked a question before using the formulation below but the scale did not was off due to the wrong operator being used so I did not ask that particular question at the time:
z1=2 * pi * 650 * 10^6
p1=2 * pi * 1.9 * 10^9
p2=2 * pi * 5 * 10^9
adc=.667
deltaF=.2 * 10^9
N=(adc * p1 * p2)/z1
M(freq)=(-2 * i * pi * freq + z1)/((-2 * i * pi * freq+p1) * (-2 * i * pi * freq+p2))
g(frq)=20 * abs(log(N * M(frq),10))
pts=[(frq,g(frq).n()) for frq in srange(10^8,10^11,deltaF)]
list_plot(pts, scale='semilogx')gjmThu, 16 Aug 2012 04:42:11 -0500https://ask.sagemath.org/question/9244/TypeError doing a contour plot of imag_part(I*log(x+I*y))https://ask.sagemath.org/question/7500/typeerror-doing-a-contour-plot-of-imag_partilogxiy/Hi. I'm trying to do a contour plot of the imaginary part of i*log(z).
z = var("z")
x,y = var("x,y",domain="real")
u = I*log(z)
f = imag_part(u(z=(x+I*y)))
contour_plot(f,(x,-3,3),(y,-3,3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_30.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eiA9IHZhcigieiIpCngseSA9IHZhcigieCx5Iixkb21haW49InJlYWwiKQp1ID0gSSpsb2coeikKZiA9IGltYWdfcGFydCh1KHo9KHgrSSp5KSkpCmNvbnRvdXJfcGxvdChmLCh4LC0zLDMpLCh5LC0zLDMpKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpk8YRSf/___code___.py", line 7, in <module>
exec compile(u'contour_plot(f,(x,-_sage_const_3 ,_sage_const_3 ),(y,-_sage_const_3 ,_sage_const_3 ))
File "", line 1, in <module>
File "/cosas/sage/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 456, in wrapper
return func(*args, **kwds)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 456, in wrapper
return func(*args, **kwds)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/misc/decorators.py", line 534, in wrapper
return func(*args, **options)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/plot/contour_plot.py", line 470, in contour_plot
g, ranges = setup_for_eval_on_grid([f], [xrange, yrange], options['plot_points'])
File "/cosas/sage/local/lib/python2.6/site-packages/sage/plot/misc.py", line 144, in setup_for_eval_on_grid
return fast_float(funcs, *vars,**options), [tuple(range+[range_step]) for range,range_step in zip(ranges, range_steps)]
File "fast_eval.pyx", line 1357, in sage.ext.fast_eval.fast_float (sage/ext/fast_eval.c:8418)
File "fast_eval.pyx", line 1372, in sage.ext.fast_eval.fast_float (sage/ext/fast_eval.c:8627)
File "fast_callable.pyx", line 420, in sage.ext.fast_callable.fast_callable (sage/ext/fast_callable.c:3173)
File "expression.pyx", line 8108, in sage.symbolic.expression.Expression._fast_callable_ (sage/symbolic/expression.cpp:30640)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1392, in fast_callable
return FastCallableConverter(ex, etb)()
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 220, in __call__
return self.composition(ex, operator)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1370, in composition
return self.etb.call(function, *ex.operands())
File "fast_callable.pyx", line 685, in sage.ext.fast_callable.ExpressionTreeBuilder.call (sage/ext/fast_callable.c:5024)
File "fast_callable.pyx", line 565, in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (sage/ext/fast_callable.c:4378)
File "expression.pyx", line 8108, in sage.symbolic.expression.Expression._fast_callable_ (sage/symbolic/expression.cpp:30640)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1392, in fast_callable
return FastCallableConverter(ex, etb)()
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 220, in __call__
return self.composition(ex, operator)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1370, in composition
return self.etb.call(function, *ex.operands())
File "fast_callable.pyx", line 685, in sage.ext.fast_callable.ExpressionTreeBuilder.call (sage/ext/fast_callable.c:5024)
File "fast_callable.pyx", line 565, in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (sage/ext/fast_callable.c:4378)
File "expression.pyx", line 8108, in sage.symbolic.expression.Expression._fast_callable_ (sage/symbolic/expression.cpp:30640)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1392, in fast_callable
return FastCallableConverter(ex, etb)()
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 214, in __call__
return self.arithmetic(ex, operator)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1332, in arithmetic
return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1332, in <lambda>
return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
File "fast_callable.pyx", line 685, in sage.ext.fast_callable.ExpressionTreeBuilder.call (sage/ext/fast_callable.c:5024)
File "fast_callable.pyx", line 565, in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (sage/ext/fast_callable.c:4378)
File "expression.pyx", line 8108, in sage.symbolic.expression.Expression._fast_callable_ (sage/symbolic/expression.cpp:30640)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1392, in fast_callable
return FastCallableConverter(ex, etb)()
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 213, in __call__
return self.arithmetic(div, div.operator())
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1332, in arithmetic
return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1332, in <lambda>
return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
File "fast_callable.pyx", line 685, in sage.ext.fast_callable.ExpressionTreeBuilder.call (sage/ext/fast_callable.c:5024)
File "fast_callable.pyx", line 565, in sage.ext.fast_callable.ExpressionTreeBuilder.__call__ (sage/ext/fast_callable.c:4378)
File "expression.pyx", line 8108, in sage.symbolic.expression.Expression._fast_callable_ (sage/symbolic/expression.cpp:30640)
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 1392, in fast_callable
return FastCallableConverter(ex, etb)()
File "/cosas/sage/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py", line 204, in __call__
raise err
TypeError: cannot convert I to real number
I get a similar error when using `1j`, except it's
TypeError: Unable to convert 1.00000000000000*I to float; use abs() or
real_part() as desired
One work-around I've found is defining `f` as a regular python function:
z = var("z")
x,y = var("x,y",domain="real")
u = I*log(z)
def f(x,y): return imag_part(u(z=(x+I*y)))
contour_plot(f,(x,-3,3),(y,-3,3))
However it is much slower than ordinary plots.ignamvFri, 13 Apr 2012 02:48:28 -0500https://ask.sagemath.org/question/7500/Solve log equations problemhttps://ask.sagemath.org/question/8783/solve-log-equations-problem/Input
var('x')
solve((log((x**2 - x), 6) - log((6*x - 10), 6) == 0), x)
Output
[log(x^2 - x) == log(6*x - 10)]
But real roots are 5 and 2. What I doing wrong?TicksyFri, 09 Mar 2012 05:36:53 -0600https://ask.sagemath.org/question/8783/log base 10https://ask.sagemath.org/question/8525/log-base-10/Is there a built-in way to use a log with base other than e? The log documentation doesn't show any example (I thought log(10,x) was what I wanted for a while but it's actually different than what one might expect). JasonThu, 01 Dec 2011 05:46:54 -0600https://ask.sagemath.org/question/8525/Unexpected behavior of log() in complex planehttps://ask.sagemath.org/question/8409/unexpected-behavior-of-log-in-complex-plane/For the log() to be defined properly in the complex plane we need to agree on where its cut is located. So, for sage it is easy to check that the cut is located on the negative Re-axis (as is most common), namely
sage: var('eps')
sage: limit(log(-1+i*eps),eps=0,dir='+')
I*pi
sage: limit(log(-1+i*eps),eps=0,dir='-')
-I*pi
Ok. Now I want to use this with symbolic variables. So I do
sage: var('w eps')
sage: forget()
sage: assume(w,'real')
sage: assume(w>0)
sage: limit(log(-w+i*eps),eps=0,dir='+')
I*pi + log(w)
sage: limit(log(-w+i*eps),eps=0,dir='-')
-I*pi + log(w)
Ok. That is correct. Now I want to get a little more adventurous, namely
sage: var('w ec eps')
sage: forget()
sage: assume(w,'real')
sage: assume(ec,'real')
sage: assume(eps,'real')
sage: assume(w>0)
sage: assume(w<ec)
sage: limit(log(w-ec+i*eps),eps=0,dir='+')
I*pi + log(-ec + w)
sage: limit(log(w-ec+i*eps),eps=0,dir='-')
-I*pi + log(-ec + w)
**Oops? This is wrong.** The argument of the log() has not been turned into the absolute value its real part, i.e. `ec-w`. This also contradicts the previous simpler startup examples.
Just for backup. Mathematica will give you
In[6]:= Limit[Log[w-ec+I eps],eps->0,Direction->-1,Assumptions->{w>0,w<ec}]
Out[6]= I Pi+Log[ec-w]
In[7]:= Limit[Log[w-ec+I eps],eps->0,Direction->1,Assumptions->{w>0,w<ec}]
Out[7]= -I Pi+Log[ec-w]
As I was expecting and at variance with sage's output.XaverSun, 23 Oct 2011 09:46:45 -0500https://ask.sagemath.org/question/8409/Plotting a loglogplothttps://ask.sagemath.org/question/8322/plotting-a-loglogplot/is there a way to create a *loglogplot*? (a 2D plot that has *both axes logarithmically scaled*)
I've found links to there bugs ([0](http://trac.sagemath.org/sage_trac/ticket/4529), [1](http://trac.sagemath.org/sage_trac/ticket/1431)), but this hasn't been much helpful.
OndraFri, 16 Sep 2011 08:27:18 -0500https://ask.sagemath.org/question/8322/ploting problemshttps://ask.sagemath.org/question/8260/ploting-problems/I want to do the plot of: log (y) vs log (x), when y = log (x) and x is between (1,150), so I tried:
sage: var ('x,y')
(x, y)
sage: y = function ('y',x)
sage: y = x^2
sage: plot (log(y), (log(x), 1,150))
but the final result that I found is wrong (I did the real plot using openoffice and gnuplot), so finally someone could you help me to solve this problem?milofisThu, 25 Aug 2011 07:20:09 -0500https://ask.sagemath.org/question/8260/How to change _latex_ of log to \ln ?https://ask.sagemath.org/question/8149/how-to-change-_latex_-of-log-to-ln/And also more changes, for example: tan to \tg, sin to \sen etc. It's very common to use this small differences in classes in Portugal.PedroFri, 03 Jun 2011 01:23:33 -0500https://ask.sagemath.org/question/8149/