0% found this document useful (0 votes)
69 views12 pages

Maths Lab Syntax

1. The document provides instructions for using various mathematical functions and operations in SageMath such as finding the factorial of a number, determining if a number is prime, plotting equations, solving systems of equations using matrices, curve fitting, and calculating integrals. 2. Examples are given for plotting single and multiple equations, implicit and parametric plots, vector fields, 3D surfaces, and calculating limits, derivatives, integrals, and solving differential equations. 3. Instructions are also provided for linear algebra operations like finding the determinant, inverse and eigenvalues of a matrix as well as verifying Cayley-Hamilton theorem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views12 pages

Maths Lab Syntax

1. The document provides instructions for using various mathematical functions and operations in SageMath such as finding the factorial of a number, determining if a number is prime, plotting equations, solving systems of equations using matrices, curve fitting, and calculating integrals. 2. Examples are given for plotting single and multiple equations, implicit and parametric plots, vector fields, 3D surfaces, and calculating limits, derivatives, integrals, and solving differential equations. 3. Instructions are also provided for linear algebra operations like finding the determinant, inverse and eigenvalues of a matrix as well as verifying Cayley-Hamilton theorem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

SAGE MATHS AS CALCULATOR

1.For finding factorial of a number

Factorial (number)

2.To find how many digits are there in a number

A=number

A.ndigits()

3.To find if a number is prime or not

Number.is_prime()

If it will be prime the output will be true if it will not be prime the output will be false

4.List of prime numbers in a given interval

List(prime(1,50))

5.How to find gcd and LCM to of two numbers

Gcd(num1, num2)

Lcm(num1,num2)

6.To find value in numeric/decimal form of any trigonometric function

Sin(45).n()

7.To show anything in mathematical form for example pi


Show(pi)

8.How to differentiate a given equation

Var('given variables in the equation')

f=given equation

• Show(diff(d, x or y)

• Show(diff(equation, x or y)

• Show(diff(equation, how many times we have to differentiate)

9.How to integrate a given function

Show(integrate(equation, x or y))

10.How to integrate if limits is given

Show(integrate(equation, x or y, the given limits))

11.How to solve a quadratic equation

var('a,b,c')

def quad(a,b,c): x1=(-b+sqrt(b**2-4*a*c))/(2*a)

x2=(-b-sqrt(b**2-4*a*c))/(2*a)

return(x1,x2)

Then we'll take a quadratic equation will take out a b and c from that equation and we will use the
quad (a,b,c)

12.How to solve linear equations with two variables


Var('the given variables')

Show(solve([equation 1, equation 2], given 2 variables))

2 3.PLOTTING

1. Syntax of plotting given equation

Var('given variables')

f=given equation

f.plot(at which point we have to plot the curve of it)

2. Other the things that we can use while plotting a curve

plot(sin(x),0,2*pi,color='red', figsize=3,title="Sinx", thickness=3, legend_label='sinx')

Where can change colour, figure size, give title or legend lable to the curve, can change the
thickness, can even edit the axes also

3.Syntax if we want to plot 3 or 4 curves together

P1=plot(equ, points, color, figsize)

P2=plot(equ, points, color, figsize)

P3=plot(equ, points, color, figsize)

P4=plot(equ, points, color, figsize)

Show(p1+p2+p3+p4)

We will use different colours to show the plot of different curves properly.

4. Scatter plot syntax

Data=[data given]
Scatter_plot(data)

5. Implicit plot syntax

var('given variables')

f(given variables)=equation

implicit_plot(f, points for which you have to plot the equation, color, figsize, etc etc)

6. Parametric plot syntax

Var('t')

Parametric_plot([equation 1, equation 2], (t, points for which we have to plot the curve))

7. Polar plots

Var('t')

Polar_plot([equation 1, equation 2], (t, points for which we have to plot the curve))

8. Vector plot

A=vector ([points for which we have to plot])

Plot(A, figsize)

9. 3D plotting

Var('given variables')

f=given equation

plot3d(f(given variables), x and y points at which we have to plot the 3d diagram)

10. If Implicit equation is given for 3D plot


Implicit_plot3d()

11. Surface of revolution

Revolution_3d(function, (x, xmin, max)

4.CALCULUS WITH SAGEMATHS

1. How to find limit

Limit(equation, x=given limit)

2. How to find derivative

Var('given variables')

F=given equation

Show(f.diff(for how many times we have to derive it))

3. Syntax for derivation and points are also given

Var('given variables')

F=given equation

Show(diff(f,x)(given points))

4. To find implicit derivative

var('given variables')

f(x,y)=given equation

show(f)

show('dy/dx=',-diff(f,x)/diff(f,y))
5. Local maxima and minima

F.find_local_maxima()

F.find_local_minima()

6. How to find the intervals where function is increasing or decreasing

First we will plot the the curve of the given equation

Var()

F=equation

Pf=plot(f, points for which we've to plot the curve)

Show(pf)

Then we will differentiate the given equation and will plot both the curve in the same graph

D=diff(f,x)

Show(d)

Pd=plot(D,points for which we've to plot the curve)

Show(pd+pf, figsize)

Then by observing the graph we can write the intervals of increasing and decreasing function

7. Syntax for critical points and point of inflation

cpts=solve(d2f==0, x, solution_dict=true)

cpts

infl=solve(d2f==0,x,solution_dict=true)
infl

We can take out the derivatives of an equation at different orders and we can plot those all curves in
a single graph to determine concave up and concave down points

6.BASICS OF LINEAR ALGEBRA

1. Defining a matrix

Show(matrix(rows, columns [elements]))

Show(matrix(ZZ, rows, columns [elements]))

ZZ shows integer field defines all elements in matrix as a integer

RR (Real Field) defines all entries in matrix is a real number

CDF (Complex Dence Field) defines all entries in matrix is a complex number

QQ (Rational Field) defines all entries in matrix is a rational number

2. Matrix operations

Define matrix P

Define matrix Q

For addition and subtraction

show('P+Q =',P+Q , 'P-Q =', P-Q)

For transpose

show('P Q = ',P*Q.transpose())
3. Syntax for finding determinant transpose a inverse adjoint of a matrix

Define matrix R

R.det()

R.inverse()

R.inverse()

R.adjugate()

R.trace()

3*R (this is for scalar multiplication)

4. How to solve a system of equation with the use of matrix

Define variables

Show(solve([equation 1, equation 2, equation 3] variables))

A=matrix([equation points])

B=vector([])

show('A= ', A , 'B= ', B.column())

C=A.augment(B)

Show('C=',C)

rank(A)==rank(C)

5. How to check if the vectors are linearly dependent or not

Define matrix U

Show matrix()
U.transpose().echelon_form()

6.eigen values and eigen vectors using characteristic equation

A=matrix()

p(x)=A.characteristic_polynomial(x)

show('p(x)=', p(x))

P(x).roots()

E=A.eigenvalues()

Show(E)

V=A.eigenvectors_right()

Show('V=', V)

Sum(E)==A.trace()

Product(E)==det(A)

Det(A)

7. Syntax for diagonal matrix

D,M=A.eigenmatrix_right()

Show('D=',D, 'M=',M)

8. How to verify cayley Hamilton theorem


A=matrix()

p(x)=A.characteristic_polynomial(x)

show('p(x)=', p(x))

Coff=p.coeifficients()

Show(coff)

show('p(A)=',sum ([ Coff[k]* A ^(k) for k in range () ]))

7.CURVE FITTING

1. Syntax for finding the best fir curve for given data

data=[(points given)]

point(data)

Then we'll define variables and we'll write equation

f1=find_fit(data)

f1

model1=y.subs(f)

model1

point(data) + plot(model1)

2. Comparing two fittings

var('given variables')

y(x) = given polynomial equation


z(x)= given polynomial equation

show(y)

show(z)

f1=find_fit(data,y,solution_dict=True)

f2=find_fit(data,z,solution_dict=True)

show(f1,f2)

model1=y.subs(f1)

model2=z.subs(f2)

show(model1)

show(model2)

Point(data) + plot(model1) + plot(model1)

8 INTEGRAL CALCULUS

1. Integrating a function

f(x)=given function

Show(integrate (f(x),x))

2. Integration if limit is given

show(integral(f(x), x, lower limit, upper limit))

3. How to find area enclosed between two curves

f(x)=given equation

g(x)=given equation
plot(f(x), points where the curve is to be plotted + plot(g(x), points where the curve is to be plotted)

S = solve(f(x) == g(x),x,solution_dict=True)

a,b = S[0][x], S[1][x]

a,b

p1= plot(f(x), (x,a,b), fill = g(x), fillcolor=)

p2=plot(g(x), (x,a,b), color=)

show(p1+p2)

Area = integral((f(x) - g(x)),x,a,b)

show(Area)

show(Area.n())

4. Syntax for finding Arc length

f(x)

Plot(f(x))

Show(integral(sqrt(1+derivative (f,x)^2), given points).n()

You might also like