Type some Sage code below and press Compute (Test examples). Choose a different language from the dropdown menu (say Macaulay2), write some code in the editor, and click the "Compute" button to run it (reload browser if you do not see the editor).
-
- Active Topics
-
-
- by Eli 2 days ago Re: What is in Your Mind? View the latest post Replies 703 Views 301882
- by Eli 2 days ago Russia Invades Ukraine View the latest post Replies 663 Views 236927
- by Eli 3 days ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 326 Views 36232
- by Eli 5 days ago PySpark for Large Data Processing View the latest post Replies 1 Views 7846
- by Eli 1 week ago President Museveni's Speech During International Development Association (IDA) Summit View the latest post Replies 1 Views 305
- by Eli 1 week ago From Simple Linear Regression Analysis to Covariance & Correlation to Independent Determinant, and R-Squared View the latest post Replies 11 Views 24908
- by Eli 1 week ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 34 Views 69050
- by Eli 2 weeks ago Pondering Big Cosmology Questions Through Lectures and Dialogues View the latest post Replies 34 Views 58220
- by Eli 2 weeks ago Programmatically Manipulate Files: Renaming, Reading, Writing, Deleting, and Moving Files Between Folders View the latest post Replies 7 Views 17289
- by Eli 2 weeks ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 19592
-
Computing with SageMath Directly from the Forum
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Try to integrate 1/(1+x^4) with Sage or Maxima, i.e., integrate(1/(1 + x^4), x);
The answer should be
\begin{equation}
\begin{split}
& \int\frac{1}{1 + x^4}{\rm d}x \\
& = 1/4\sqrt{2}\times{\rm tan}^{-1}\left(1/2\sqrt{2}\times(2x + \sqrt{2})\right) + 1/4\sqrt{2}\times {\rm tan}^{-1}\left(1/2\times \sqrt{2}\times(2x - \sqrt{2})\right)\\
& + 1/8\sqrt{2}\times{\rm log}(x^2 + \sqrt{2}\times x + 1) - 1/8\sqrt{2}\times{\rm log}(x^2 - \sqrt{2}\times x + 1)
\end{split}
\end{equation}
Try this in Macaulay2:
The answer should be
\begin{equation}
\begin{split}
& \int\frac{1}{1 + x^4}{\rm d}x \\
& = 1/4\sqrt{2}\times{\rm tan}^{-1}\left(1/2\sqrt{2}\times(2x + \sqrt{2})\right) + 1/4\sqrt{2}\times {\rm tan}^{-1}\left(1/2\times \sqrt{2}\times(2x - \sqrt{2})\right)\\
& + 1/8\sqrt{2}\times{\rm log}(x^2 + \sqrt{2}\times x + 1) - 1/8\sqrt{2}\times{\rm log}(x^2 - \sqrt{2}\times x + 1)
\end{split}
\end{equation}
Try this in Macaulay2:
- R = QQ[x,y,z]
- curve = ideal( x^4-y^5, x^3-y^7 )
- gb curve
- dim curve
- degree curve
- curve1 = saturate(curve,ideal(x))
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Test these solutions in Sage (see reference manual here):
The output is:
Solve system of ODEs:
- x,y,z=var('x,y,z')
- # Next we define the parameters
- sigma=10
- rho=28
- beta=8/3
- # The Lorenz equations
- lorenz=[sigma*(y-x),x*(rho-z)-y,x*y-beta*z]
- # Time and initial conditions
- times=srange(0,50.05,0.005)
- ics=[0,1,1]
- sol=desolve_odeint(lorenz,ics,times,[x,y,z],rtol=1e-13,atol=1e-14)
- vis=line(zip(sol[:,0],sol[:,1]))
- vis.show()
The output is:
- #from sage.calculus.desolvers import desolve_odeint -- optional
- x,y=var('x,y')
- f=[x*(1-y),-y*(1-x)]
- sol=desolve_odeint(f,[0.5,2],srange(0,10,0.1),[x,y])
- vis=line(zip(sol[:,0],sol[:,1]))
- print(sol)
- vis.show()
- #y = function('y')(x)
- #eq = diff(y,x) - (x - 2)/(y^2 + 1)*sin(x - 2) - sin(y) == 0
- #desolve_laplace(eq,y,ics=[0,3])
- y1,y2,y3=var('y1,y2,y3')
- f1=77.27*(y2+y1*(1-8.375*1e-6*y1-y2))
- f2=1/77.27*(y3-(1+y1)*y2)
- f3=0.16*(y1-y3)
- f=[f1,f2,f3]
- ci=[0.2,0.4,0.7]
- t=srange(0,10,0.01)
- v=[y1,y2,y3]
- sol=desolve_odeint(f,ci,t,v,rtol=1e-3,atol=1e-4,h0=0.1,hmax=1,hmin=1e-4,mxstep=1000,mxords=17)
- print(sol)
Solve system of ODEs:
- t = var('t')
- x = function('x')(t)
- y = function('y')(t)
- de1 = diff(x,t) + y - 1 == 0
- de2 = diff(y,t) - x + 1 == 0
- sol = desolve_system([de1, de2], [x,y])
- #Add ics if you want
- #sol = desolve_system([de1, de2], [x,y],ics=[0,0.5,1],ivar=t)
- print(sol)
- from sage.calculus.desolvers import desolve_system_rk4
- x,y,t=var('x y t')
- P=desolve_system_rk4([x*(1-y),-y*(1-x)],[x,y],ics=[0,0.5,2],ivar=t,end_points=20)
- Q=[ [i,j] for i,j,k in P]
- LP=list_plot(Q)
- Q=[ [j,k] for i,j,k in P]
- LP=list_plot(Q)
- plot(LP)
- var('t,x,y,X,Y')
- f(t,x,y,X,Y)=[X, Y, -x/(x^2+y^2)^(3/2), -y/(x^2+y^2)^(3/2)]
- ics = [0.8, 0, 0, 1.22474487139159]
- t = 100*pi
- sol = desolve_mintides(f, ics, 0, t, t, 1e-12, 1e-12) # optional -tides
- sol # optional -tides # abs tol 1e-5
- Attachments
-
- Lorentz.png
- (99.22 KiB) Not downloaded yet
- Lorentz.png
- (99.22 KiB) Not downloaded yet
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Plotting in Sage (see more from here):
See the attached outputs.
Code: Select all
f(x) = (x-3)*(x-5)*(x-7)+40
P = line([(2,0),(2,f(2))], color='black')
P += line([(8,0),(8,f(8))], color='black')
P += polygon([(2,0),(2,f(2))] + [(x, f(x)) for x in [2,2.1,..,8]] + [(8,0),(2,0)], rgbcolor=(0.8,0.8,0.8),aspect_ratio='automatic')
P += text("$\\int_{a}^b f(x) dx$", (5, 20), fontsize=16, color='black')
P += plot(f, (1, 8.5), thickness=3)
P # show the result
- var("x y")
- G = Graphics()
- counter = 0
- for col in colors.keys(): # Long time
- G += implicit_plot(x^2 + y^2 == 1 + counter*.1, (x,-4,4),(y,-4,4), color=col)
- counter += 1
- G
- var("x y")
- contour_plot(y^2 + 1 - x^3 - x, (x,-pi,pi), (y,-pi,pi), fill=False, cmap='hsv', labels=True)
- var("x y")
- parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], (x,0, 8*pi), fill=True)
- def b(n): return lambda x: bessel_J(n, x)
- plot([b(n) for n in [1..5]], 0, 20, fill='axis')
See the attached outputs.
- Attachments
-
- Contour.png (359.73 KiB) Viewed 44515 times
- Contour.png (359.73 KiB) Viewed 44515 times
-
- Contour2.png (38.63 KiB) Viewed 44515 times
- Contour2.png (38.63 KiB) Viewed 44515 times
-
- Parametric_plot.png (26.95 KiB) Viewed 44512 times
- Parametric_plot.png (26.95 KiB) Viewed 44512 times
-
- Bessel.png
- (84.12 KiB) Not downloaded yet
- Bessel.png
- (84.12 KiB) Not downloaded yet
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Try to solve
\begin{equation}
\frac{{\rm d}y}{{\rm d}x} = \frac{x - 2}{y^2 + 1}\times {\rm sin}(x - 2) - {\rm sin}(y).
\end{equation}
\begin{equation}
\frac{{\rm d}y}{{\rm d}x} = \frac{x - 2}{y^2 + 1}\times {\rm sin}(x - 2) - {\rm sin}(y).
\end{equation}
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
We can label and decorate our plots:
- x,y,z=var('x,y,z')
- # Next we define the parameters
- sigma=10
- rho=28
- beta=8/3
- # The Lorenz equations
- lorenz=[sigma*(y-x),x*(rho-z)-y,x*y-beta*z]
- # Time and initial conditions
- times=srange(0,50.05,0.005)
- ics=[0,1,1]
- sol=desolve_odeint(lorenz,ics,times,[x,y,z],rtol=1e-13,atol=1e-14)
- vis=line(zip(sol[:,0],sol[:,1]), color='purple')
- vis.axes_labels(['X axis', 'Y axis'])
- vis.legend(False)
- vis.show(title='Lorenz Equations', frame=True, legend_loc="lower right")
- vis.show()
- Attachments
-
- Lorenz_systems.png
- (120.12 KiB) Not downloaded yet
- Lorenz_systems.png
- (120.12 KiB) Not downloaded yet
-
- Lorenz_system2.png
- (124.85 KiB) Not downloaded yet
- Lorenz_system2.png
- (124.85 KiB) Not downloaded yet
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Try the following Algebra problems in Sage:
Example 1: Transpose of a Matrix
Example 2: LU Factorization of a Matrix
Example 3: Modified Gram-Schmidt Algorithm -- QR decomposition
See more examples here.
Example 1: Transpose of a Matrix
- A = matrix(QQ, 5, range(25))
- A.T
Example 2: LU Factorization of a Matrix
- A = matrix(QQ, [[ 2, 1, 1],
- [ 4,-6, 0],
- [-2, 7, 2]])
- (P,L,U) = A.LU()
- #table([[A, '=', P, '$\\cdot$', L, '$\\cdot$', U]])
- print(P, L, U, sep='\n')
- A = matrix(QQ, [[ 2, 1, 1],
- [ 4,-6, 0],
- [-2, 7, 2]])
- (P,L,U) = A.LU(pivot='nonzero')
- #table([[A, '=', P, '$\\cdot$', L, '$\\cdot$', U]])
- print(P, L, U, sep='\n')
- A = matrix(QQ, [[ 1, -4, 1, 0, -2, 1, 3, 3, 2],
- [-1, 4, 0, -4, 0, -4, 5, -7, -7],
- [ 0, 0, 1, -4, -1, -3, 6, -5, -6],
- [-2, 8, -1, -4, 2, -4, 1, -8, -7],
- [ 1, -4, 2, -4, -3, 2, 5, 6, 4]])
- P, L, U = A.LU()
- U
- A.rref()
- A.pivots()
- D = matrix(QQ, [[ 1, 0, 2, 0, -2, -1],
- [ 3, -2, 3, -1, 0, 6],
- [-4, 2, -3, 1, -1, -8],
- [-2, 2, -3, 2, 1, 0],
- [ 0, -1, -1, 0, 2, 5],
- [-1, 2, -4, -1, 5, -3]])
- P, L, U = D.LU(pivot='nonzero')
- P
- L
- U
- D == L*U
Example 3: Modified Gram-Schmidt Algorithm -- QR decomposition
- A = matrix(QQbar, [[-2, 0, -4, -1, -1],
- [-2, 1, -6, -3, -1],
- [1, 1, 7, 4, 5],
- [3, 0, 8, 3, 3],
- [-1, 1, -6, -6, 5]])
- Q, R = A.QR()
- Q
- R
- Q.conjugate_transpose()*Q
- Q*R == A
See more examples here.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Knots Using Sage:
- B = BraidGroup(4)
- K = Knot(B([1,1,1,2,-1,2,-3,2,-3]))
- plot(K)
- K.alexander_polynomial()
- K.jones_polynomial()
- K.determinant()
- K.signature()
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5382
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Interactive Fourier Series with Sage (see source):
- ## Interactive Fourier Series, via: http://www.walkingrandomly.com/?p=1879
- def ftermSquare(n):
- return(1/n*sin(n*x*pi/3))
- def ftermSawtooth(n):
- return(1/n*sin(n*x*pi/3))
- def ftermParabola(n):
- return((-1)^n/n^2 * cos(n*x))
- def fseriesSquare(n):
- return(4/pi*sum(ftermSquare(i) for i in range (1,2*n,2)))
- def fseriesSawtooth(n):
- return(1/2-1/pi*sum(ftermSawtooth(i) for i in range (1,n)))
- def fseriesParabola(n):
- return(pi^2/3 + 4*sum(ftermParabola(i) for i in range(1,n)))
- @interact
- def plotFourier(n=slider(1, 30,1,3,'Number of terms')
- ,Function=['Square Wave','Saw Tooth','Periodic Parabola']):
- if Function=='Saw Tooth':
- show(plot(fseriesSawtooth(n),x,-6,6,figsize=(7,3)))
- if Function=='Square Wave':
- show(plot(fseriesSquare(n),x,-6,6,figsize=(7,3)))
- if Function=='Periodic Parabola':
- show(plot(fseriesParabola(n),x,-6,6,figsize=(7,3)))
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests