ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 12 Apr 2011 14:31:35 +0200Translationhttps://ask.sagemath.org/question/8047/translation/y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2);
and
NumberForm[N[\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-1\), \(1\)]\(f[
x] \[DifferentialD]x\)\)], 12]
Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$
Please help me translate this into SAGE. Thank You!!Sat, 02 Apr 2011 18:37:46 +0200https://ask.sagemath.org/question/8047/translation/Comment by John Palmieri for <p>y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2); </p>
<p>and </p>
<p>NumberForm[N[!(
*SubsuperscriptBox[([Integral]), (-1), (1)](f[
x] [DifferentialD]x))], 12]</p>
<p>Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$</p>
<p>Please help me translate this into SAGE. Thank You!!</p>
https://ask.sagemath.org/question/8047/translation/?comment=21925#post-id-21925For those of us who don't know Mathematica syntax, could you also explain what you're trying to do in words?Sat, 02 Apr 2011 19:09:48 +0200https://ask.sagemath.org/question/8047/translation/?comment=21925#post-id-21925Comment by Simon for <p>y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2); </p>
<p>and </p>
<p>NumberForm[N[!(
*SubsuperscriptBox[([Integral]), (-1), (1)](f[
x] [DifferentialD]x))], 12]</p>
<p>Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$</p>
<p>Please help me translate this into SAGE. Thank You!!</p>
https://ask.sagemath.org/question/8047/translation/?comment=21923#post-id-21923Can you rewrite your Mathematica code in InputForm so that it can be easily read and copied? That said, the code that you've posted does not seem to do anything. Can you post a working example?Sat, 02 Apr 2011 20:10:40 +0200https://ask.sagemath.org/question/8047/translation/?comment=21923#post-id-21923Comment by cswiercz for <p>y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2); </p>
<p>and </p>
<p>NumberForm[N[!(
*SubsuperscriptBox[([Integral]), (-1), (1)](f[
x] [DifferentialD]x))], 12]</p>
<p>Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$</p>
<p>Please help me translate this into SAGE. Thank You!!</p>
https://ask.sagemath.org/question/8047/translation/?comment=21853#post-id-21853If a numerical solution is all you need you might want to try using Scipy. You can find out more about Scipy's numerical integration methods at: http://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html . Scipy comes included with Sage.Tue, 12 Apr 2011 14:31:35 +0200https://ask.sagemath.org/question/8047/translation/?comment=21853#post-id-21853Comment by Simon for <p>y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2); </p>
<p>and </p>
<p>NumberForm[N[!(
*SubsuperscriptBox[([Integral]), (-1), (1)](f[
x] [DifferentialD]x))], 12]</p>
<p>Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$</p>
<p>Please help me translate this into SAGE. Thank You!!</p>
https://ask.sagemath.org/question/8047/translation/?comment=21909#post-id-21909@Sagud: Posting Mma Box structure is no good. It is basically unreadable. In Mma, select the text you want to copy, right click and go "Copy As > Input Text". You can edit your post and paste in the code using a code markup. Make it readable and people might be more inclined to help.Sun, 03 Apr 2011 23:05:21 +0200https://ask.sagemath.org/question/8047/translation/?comment=21909#post-id-21909Comment by kcrisman for <p>y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2); </p>
<p>and </p>
<p>NumberForm[N[!(
*SubsuperscriptBox[([Integral]), (-1), (1)](f[
x] [DifferentialD]x))], 12]</p>
<p>Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$</p>
<p>Please help me translate this into SAGE. Thank You!!</p>
https://ask.sagemath.org/question/8047/translation/?comment=21905#post-id-21905Incidentally, you can edit your original post and put it there!Mon, 04 Apr 2011 11:58:15 +0200https://ask.sagemath.org/question/8047/translation/?comment=21905#post-id-21905Comment by benjaminfjones for <p>y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2); </p>
<p>and </p>
<p>NumberForm[N[!(
*SubsuperscriptBox[([Integral]), (-1), (1)](f[
x] [DifferentialD]x))], 12]</p>
<p>Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$</p>
<p>Please help me translate this into SAGE. Thank You!!</p>
https://ask.sagemath.org/question/8047/translation/?comment=21888#post-id-21888Somehow the original question has become mangled. All I see is the integral of f(x) from -1 to 1.Wed, 06 Apr 2011 18:38:16 +0200https://ask.sagemath.org/question/8047/translation/?comment=21888#post-id-21888Answer by kcrisman for <p>y = x /. NSolve[LegendreP[i, x] == 0, x];
z = (2 (1 - y^2))/((i + 1)^2 LegendreP[i + 1, y]^2); </p>
<p>and </p>
<p>NumberForm[N[!(
*SubsuperscriptBox[([Integral]), (-1), (1)](f[
x] [DifferentialD]x))], 12]</p>
<p>Edit: I think the OP means $$\int_{-1}^1 f(x)\;dx$$</p>
<p>Please help me translate this into SAGE. Thank You!!</p>
https://ask.sagemath.org/question/8047/translation/?answer=12251#post-id-12251There is no direct equivalent in Sage to this, but I'll try to give a few ideas for how to do what you want.
Most directly, this will help:
sage: solve(legendre_P(9,x),x)[0].rhs().n()
-0.968160239507626 + 2.33721339925049e-18*I
sage: solve(legendre_P(9,x),x)[0].rhs().n(prec=100)
-0.96816023950762608983557620291 + 2.7752069983964298759432951970e-32*I
Assuming that's right. `solve` only gives symbolic solutions in this case, so we get at the numerical approximation this way; for high-accuracy numerical solutions immediately, use `find_root`.
sage: find_root(legendre_P(9,x),-1,-.9)
-0.96816023950880892
Unfortunately, I have to do `legendre_P(9,x)` and not
sage: j = var('j')
sage: F = legendre_P(j,x)
because we do not have it wrapped in a way that allows that, though presumably we could do so. Our special and other functions can use upgrading from that standpoint. In Maxima one might be able to do that directly, though.
Finally, if your last question is asking how to numerically approximate integrals, there are lots of good ways to do this. If you have a symbolic integral with endpoints, using `.n()` should work to approximate it; a function worth checking out is `numerical_integral`.Sat, 02 Apr 2011 23:23:28 +0200https://ask.sagemath.org/question/8047/translation/?answer=12251#post-id-12251