Ask Your Question

ianhi's profile - activity

2020-03-11 03:14:11 -0500 received badge  Notable Question (source)
2020-02-13 00:21:03 -0500 received badge  Notable Question (source)
2018-12-06 11:55:43 -0500 received badge  Popular Question (source)
2018-07-26 13:59:34 -0500 received badge  Popular Question (source)
2015-11-14 12:17:35 -0500 received badge  Supporter (source)
2015-11-07 15:29:11 -0500 commented answer How to push from the cloud to github?

You can create a .term file from the interface brought up by the "+New" button on the top left, then choose the ">_terminal" button. This gives you a full interactive linux command line.

2015-11-04 14:22:11 -0500 answered a question How to push from the cloud to github?

Hi, I am experiencing the same error as you when I use the terminal window in the top right of the file browser. Based on this thread I think the issue has something to do with whether you are connecting to github via ssh or https.

WORKAROUND: The workaround is very simple:
1. Make a .term file instead of using the terminal box
2. use the .term file to run your git command

This worked for me, I hope it solves your problem

2015-10-29 10:24:54 -0500 received badge  Teacher (source)
2015-10-29 01:32:52 -0500 answered a question symbolic and numeric double integration method

I'm interpreting your question as: Is there a sage function which will give a symbolic solution to an integral if a closed form exists and a numeric solution otherwise. To my knowledge there is not though the following function may be what you are asking for:

def sym_or_num_Integral(f,variables,lower_bound=[None],upper_bound=[None]):
    if isinstance(variables,list):
        if not isinstance(lower_bound,list):
        while len(lower_bound)!=len(variables):
            if len(lower_bound)>len(variables): break

        if not isinstance(upper_bound,list):
        while len(upper_bound) != len(variables):
            if len(lower_bound)>len(variables): break

        if len(variables)==1:
            return sym_or_num_Integral(f,variables[0],lower_bound[0],upper_bound[0])
        return sym_or_num_Integral(sym_or_num_Integral(f,*inputs_inner),*inputs_outer)

    if 'integrate' in str(result):
        return result.n()
        return result

The method of checking if the solution is a closed form is quite hacky and I'd welcome and improvement too it. This function can do any number of integrals so long as you input the parameters as a list, i.e. variables=[x,y], lower_bound=[x_lower,y_lower]. Two examples:

sage: var('x y')
sage: sym_or_num_Integral(sin(x)*y,[x,y],[0,0],[2,2])
-2*cos(2) + 2
sage: sym_or_num_Integral(sin(x*y),[x,y],[0,0],[2,2])

You can have the integral be definite in any subset (must include first variable) of the variable and not the others:

sage: sym_or_num_Integral(sin(x)*y,[x,y],[0,None],[2,None])
-1/2*y^2*(cos(2) - 1)

Was this all you were looking for?

2015-10-28 23:35:47 -0500 commented question symbolic and numeric double integration method

Can you define what you mean by good? Do you mean one that won't return integrate(....)? It seems that sage will always return integrate(...) when there is no closed form solution.


#No closed form
sage: integral(integral(sin(x*y),x,0,2),y,0,2)
integrate(-cos(2*y)/y + 1/y, y, 0, 2)

#has closed form solution
sage: integral(integral(sin(x)*y,x,0,2),y,0,2)
-2*cos(2) + 2

If what you want is the closed form solution when that is avaliable and a numeric solution the following function should suffice:

def sym_or_num_Integral(f,variable,lower_bound=None,upper_bound=None):
    if 'integrate' in str(result):
        return result.n()
        return result
2015-10-28 22:34:28 -0500 asked a question derivative of order var('m') returns 0

In mathematica I can differentiate a function m times with respect to x, where m doesn't have an explicit value yet and get an expression that can be evaluated as below:

in[0] g = x^2 + 3/2*(x^2 - 1)*x
f = D[g, {x, m}]
out[0]= ∂(x,m)(3/2x(-1+x^2))+Power(m,0)[x,2]

in[1]  f /. {m -> 2}
out[1]= 2+9x

What I believe to be the equivalent code in sage will only give me 0 instead of an expression which I could then evaluate by setting m=2:

#Sage example 1
sage: g = x^2 + 3/2*(x^2 - 1)*x
sage: var('m')
sage: diff(g,x,m)

I know it is possible to differentiate a variable number of times due to the following:

#Sage example 2
sage: diff((x^2-1)^n,x,n)
2*(x^2 - 1)^(n - 1)*n*x*log(x^2 - 1) + 2*(x^2 - 1)^(n - 1)*x

I think that example 2 works because I have x raised to the power n.

Is it possible to accomplish the equivalent of what I did in mathematica in sage (i.e. have example 1 not return 0)? Alternatively if this is not possible what advice do you have for how I could work on making this functionality exist?

Thanks in advance.

2015-10-26 21:41:06 -0500 received badge  Scholar (source)
2015-10-26 21:41:01 -0500 commented answer Legendre_P in symbolic function - recursion error

This works thanks! I wonder if you have any insights into what went wrong with my initial method and how it is that your edit fixes this? Thank you again for your time and effort very much appreciated.

2015-10-26 20:49:06 -0500 commented answer Legendre_P in symbolic function - recursion error

Thank you so much for your answer and time it's introduced me to some aspect of sage I was unaware of. Sorry for poorly phrasing the question however I think I can clarify. I would like print(f) to give me an answer fully expanded, not in terms of my_legendre(). A simpler example would be:

sage: var('y_max')
sage: Y_fnc(x,y_max,l,m)=y_max*cos(x)^3
sage: f(x,y_max,l,m)=Y_fnc(x,y_max,l,m) * cos(x)^4 -2*sqrt(Y_fnc(x,y_max,l,m))*sin(x)*cos(x)^3 
sage: print(f)
(x, y_max, l, m) |--> y_max*cos(x)^7 -2*sqrt(y_max*cos(x)^3)*cos(x)^3*sin(x)
sage: plot(f(x,y_max))

Which will print the expanded output as above an plot with the only errors being imaginary parts. This is for Neutron scattering analysis btw.

2015-10-26 20:30:04 -0500 received badge  Student (source)
2015-10-26 20:29:58 -0500 received badge  Editor (source)
2015-10-26 15:11:06 -0500 asked a question Legendre_P in symbolic function - recursion error

Undergraduate Physics mathemtica->sage convert here trying to use sage for both symbolic substitution to print equations and to plot.

I have the equation M_y^2 * cos(x)^4 -2*My(x)*sin(x)*cos(x)^3 and would like to see how this behaves when substituting different associated legendre polynomials for My^2. Code for this:

f(x,y_max,l,m)=Y_fnc(x,y_max,l,m) * cos(x)^4 -2*sqrt(Y_fnc(x,y_max,l,m))*sin(x)*cos(x)^3
Which results in: [...] File "/home/ian/sage-6.8-x86_64-Linux/local/lib/python2.7/site-packages/sage/symbolic/", line 319, in symbol raise NotImplementedError("symbol") RuntimeError: maximum recursion depth exceeded while calling a Python object With example line of the truncated output being:
File "/home/ian/sage-6.8-x86_64-Linux/local/lib/python2.7/site-packages/sage/functions/", line 1239, in gen_legendre_P
return sqrt(1-x**2)*(((n-m+1)*x*gen_legendre_P(n,m-1,x)-(n+m-1)*gen_legendre_P(n-1,m-1,x))/(1-x**2))
I have also tried to use maxima.assoc_legendre_P but this doesn't work when I try to plot:
f(x,y_max,l,m)=Y_fnc(x,y_max,l,m) * cos(x)^4 -2*sqrt(Y_fnc(x,y_max,l,m))*sin(x)*cos(x)^3 

verbose 0 (2716:, generate_plot_points) WARNING: When plotting, failed to evaluate function at 200 points.
verbose 0 (2716:, generate_plot_points) Last error message: 'unable to simplify to float approximation'

I can accomplish plotting by defining Python Functions:

    def Y_fnc_py(x,l,m,y_max):
        return y_max*gen_legendre_P(l,m,cos(x))
    def f(x,y_max,l,m):
       return Y_fnc_py(x,y_max,l,m) * cos(x)^4 -2*sqrt(Y_fnc_py(x,y_max,l,m))*sin(x)*cos(x)^3 

Works however this will not allow me print f(x,y_max,l=3,m=2) so I can easily write down the equation. So this allows me to plot easily but doesn't display the equation well Help much appreciated thank you