Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
570 views
License: GPL3
ubuntu2204
Kernel: SageMath 9.6

\hspace{20pt}Experiment Number 1

AIM: To Use SageMath as Advanced Calculator

Name: Snehal G Rakas
Roll no: 61
Section: E
Date: 8/05/2023

Basic numerical Computations

454672-258252
196420
56455+678978
735433
565*676
381940

759**11 Returns 11th power of 759

759**11
48157012271803961449924277680359
81^(1/4)
3
(79/12)
79/12
(79/12.0)
6.58333333333333
(79/12).n()
6.58333333333333
79//12
6
(79%12)
7
(sin(81)).n(digits=20)
-0.62988799427445387857
(sin(81.0))
-0.629887994274454
cos(-5.3)
0.554374336179161
tan(1/2.0)
0.546302489843790
asin(-0.2)
-0.201357920790331
exp(1.0)
2.71828182845905
pi.n(digits=50)
3.1415926535897932384626433832795028841971693993751
F=factorial(576)
print(F)
4256894463620625471399338897976462846890230941821769298896221080707434902055990415666782999834652467105561645005135247510594550578570361904546802042930914680310390642433197638242918512304047044258861660945550782976855100391711791398500713833285909054634688620911207051946259440915349012504839365184529533518755428177370879723111743622910445124706269593256104219501887578284982300380039220456095383116526730085743873032838237773072593976177499478159793530051818413365412709223554005276531798500164384916741118247588065706396358679530916434991681240368497544405247600864215548296506680601289148053255684716608821820352021050028244591277208996891498042521087458841329716703518091675689367527272995883290329676158091022259824243125389761208343649293452081505395610821671083260346432722100756628487076760917971350441734334132117633025186198636599163163040922447934465322909545018661306558666998323928906394462759431335113344451854455546674490813919856400793256248896167909254939021724785145027873918136392996266973257470068635273673116279231080146181208818573897317247122622658823827561947836713192608335310969980444617575725662453866484897648923060190912757314122770275982764251413066524055645779981762560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
F.ndigits()
1342
w=F.digits()
w[0]
0
w[1]
0

Defining Variables

a=2345 b=4567 print(a,b)
2345 4567
first_number = 4565748 second_number = 45366673 p=first_number*second_number
b.is_prime()
True
b.factor()
4567
gcd(a,b)
1
lcm(a,b)
10709615
list(primes(50,100))
[53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

nth_prime(100)
541

Defining Functions

f(x)=sin(x^2)*exp(-x)+3*x+1
f(2.1)
7.18309969277139
f.diff()
x |--> 2*x*cos(x^2)*e^(-x) - e^(-x)*sin(x^2) + 3
f.diff(3)
x |--> -8*x^3*cos(x^2)*e^(-x) + 12*x^2*e^(-x)*sin(x^2) + 6*x*cos(x^2)*e^(-x) - 12*x*e^(-x)*sin(x^2) - 6*cos(x^2)*e^(-x) - e^(-x)*sin(x^2)
f.integral(x)
x |--> 3/2*x^2 - 1/16*sqrt(pi)*((-(I + 1)*sqrt(2)*cos(1/4) + (I - 1)*sqrt(2)*sin(1/4))*erf(-1/2*(-1)^(3/4)*(2*I*x + 1)) + (-(I + 1)*sqrt(2)*cos(1/4) + (I - 1)*sqrt(2)*sin(1/4))*erf(-(1/4*I - 1/4)*sqrt(2)*(2*I*x + 1)) + ((I - 1)*sqrt(2)*cos(1/4) - (I + 1)*sqrt(2)*sin(1/4))*erf(-(1/4*I + 1/4)*sqrt(2)*(2*I*x - 1)) + (-(I - 1)*sqrt(2)*cos(1/4) + (I + 1)*sqrt(2)*sin(1/4))*erf(1/2*(2*I*x - 1)/sqrt(-I))) + x
var('x,y') h(x,y)=sin(x^2-y^2) h(1.0,2.0)
-0.141120008059867
var('a,b,c') show((solve(a*x^2+b*x+c==0,x)))

[x=−b+b2−4 ac2 a,x=−b−b2−4 ac2 a]\displaystyle \left[x = -\frac{b + \sqrt{b^{2} - 4 \, a c}}{2 \, a}, x = -\frac{b - \sqrt{b^{2} - 4 \, a c}}{2 \, a}\right]

var('x1,x2') solve([3*x1-2*x2==7,2*x1+3*x2==11],x1,x2)
[[x1 == (43/13), x2 == (19/13)]]
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)
a,b,c=2,3,-2 x1,x2=quad(a,b,c) show(f'The roots of the quadratic are {x1} and {x2}')

The roots of the quadratic are 1/2 and -2\displaystyle \verb|The|\verb| |\verb|roots|\verb| |\verb|of|\verb| |\verb|the|\verb| |\verb|quadratic|\verb| |\verb|are|\verb| |\verb|1/2|\verb| |\verb|and|\verb| |\verb|-2|

show((x1.n())),(x2).n()

0.500000000000000\displaystyle 0.500000000000000

(None, -2.00000000000000)
def Heron(a,b,c): s=(a+b+c)/2.0 A=sqrt(s*(s-a)*(s-b)*(s-c)) return A
a,b,c=3,7,9 Area=Heron(a,b,c) print(f'The area of Triangle is {Area.n()}')
The area of Triangle is 8.78564169540279
#Find the sum of first 50 numbers k=0 for i in range (1,51): k=k+i k
1275
#1.Find the roots of: var('x') solve(x^3-2*x^2-5*x+6==0,x)
[x == 3, x == -2, x == 1]
#2.Solve the system of non-linear equations var('x,y') solve([(x^2-y^2==4),(y==(x^2)-2)],x,y)
[[x == -sqrt(1/2*I*sqrt(7) + 5/2), y == 1/2*I*sqrt(7) + 1/2], [x == sqrt(1/2*I*sqrt(7) + 5/2), y == 1/2*I*sqrt(7) + 1/2], [x == -sqrt(-1/2*I*sqrt(7) + 5/2), y == -1/2*I*sqrt(7) + 1/2], [x == sqrt(-1/2*I*sqrt(7) + 5/2), y == -1/2*I*sqrt(7) + 1/2]]
var('x,y') eq1 = x^2 - y^2 == 4 eq2 = y == x^2 - 2 sol = solve([eq1, eq2], x, y) sol
[[x == -sqrt(1/2*I*sqrt(7) + 5/2), y == 1/2*I*sqrt(7) + 1/2], [x == sqrt(1/2*I*sqrt(7) + 5/2), y == 1/2*I*sqrt(7) + 1/2], [x == -sqrt(-1/2*I*sqrt(7) + 5/2), y == -1/2*I*sqrt(7) + 1/2], [x == sqrt(-1/2*I*sqrt(7) + 5/2), y == -1/2*I*sqrt(7) + 1/2]]
F=factorial(1275)

1410188200745141400252996925676992827609427883860681102196565498836336759274700571301062342565763667730574384945641799898255183843797277503390234956935070394479008695945171075361751490266255689101148400638952696890761606725201668092011058223584197411362725808136521522042355331881040677201517524336650583177256411366707450357076114921552137231355444540586815705134573123811035652300829258848866779288445345880939714666466690931600352950947986039996432744118754275201288974846584827623137897792122234828866268708808373651276334848174069438274783771825876627128631153710955178645802336438821598373242525172486367974756812461614902930111917189057714749908028994429977492262359339566774968421933826661845573051906637774350159842777201017432451096856729583848901554363821690871963837317325736243872364148002548730698225622458872512196920911448958125730334065147981692621576246557948729307409911196659268977449824737887320133166571859768610902901473947123457650502571110106359050311523447786812407139365812881583625481044458877349531018685432954716465488394115659122958734526255536933591914359738150594232473711291251674238772555271930793815825985192385373959108468804902794091333308997906654387218990210896432316359969692946647542629459647405723220544167040523889230769503152154177529658591214286091920818334885793018545403374623359640495796839709709384014013012687979103444399633192318216277501509029976296018451103357572826768431048432485483904156377949766394422704783101532471054714207760435511464546800957250453788222377134546592645406967452675959535949763038875966331731971129199721214052529127807792669916640919732183579343359239597918703189536631735584104688709458017493330567389003035699210216919159335873580170482127718603055097898778534952746567262220574405875417584645973964359858336242322940751239914457356958486503721361054938154425602356741007273505642819375318812777259929805604278204113178492040885487253497253599744730743581176164725418840085566636342828519091247494824276253539056065078460524088183488674664479782491935751641451986001983862705359408369452209318497499455387591386320304376709778016052197826525984538725046076767350582105555907369126126599357472133535283786257752742361071712371083162246333227880188819486706970859272715412889313443305257503562357007473653496252819471178088373765780168140628517776493336902711979149445247736765162103192806316969933073702060508523674642586433795221440274867588588796999943822914833791154288328704000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\displaystyle 1410188200745141400252996925676992827609427883860681102196565498836336759274700571301062342565763667730574384945641799898255183843797277503390234956935070394479008695945171075361751490266255689101148400638952696890761606725201668092011058223584197411362725808136521522042355331881040677201517524336650583177256411366707450357076114921552137231355444540586815705134573123811035652300829258848866779288445345880939714666466690931600352950947986039996432744118754275201288974846584827623137897792122234828866268708808373651276334848174069438274783771825876627128631153710955178645802336438821598373242525172486367974756812461614902930111917189057714749908028994429977492262359339566774968421933826661845573051906637774350159842777201017432451096856729583848901554363821690871963837317325736243872364148002548730698225622458872512196920911448958125730334065147981692621576246557948729307409911196659268977449824737887320133166571859768610902901473947123457650502571110106359050311523447786812407139365812881583625481044458877349531018685432954716465488394115659122958734526255536933591914359738150594232473711291251674238772555271930793815825985192385373959108468804902794091333308997906654387218990210896432316359969692946647542629459647405723220544167040523889230769503152154177529658591214286091920818334885793018545403374623359640495796839709709384014013012687979103444399633192318216277501509029976296018451103357572826768431048432485483904156377949766394422704783101532471054714207760435511464546800957250453788222377134546592645406967452675959535949763038875966331731971129199721214052529127807792669916640919732183579343359239597918703189536631735584104688709458017493330567389003035699210216919159335873580170482127718603055097898778534952746567262220574405875417584645973964359858336242322940751239914457356958486503721361054938154425602356741007273505642819375318812777259929805604278204113178492040885487253497253599744730743581176164725418840085566636342828519091247494824276253539056065078460524088183488674664479782491935751641451986001983862705359408369452209318497499455387591386320304376709778016052197826525984538725046076767350582105555907369126126599357472133535283786257752742361071712371083162246333227880188819486706970859272715412889313443305257503562357007473653496252819471178088373765780168140628517776493336902711979149445247736765162103192806316969933073702060508523674642586433795221440274867588588796999943822914833791154288328704000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

#4.Find the fators of sum of digits of 1275! n = factorial(1275) t_sum = sum(int(d) for d in str(n)) t_sum factors = [] for i in range(1, t_sum+1): if t_sum % i == 0: factors.append(i) factors
[1, 2, 3, 4, 6, 7, 8, 9, 12, 14, 18, 21, 24, 27, 28, 36, 42, 54, 56, 63, 72, 81, 84, 108, 126, 162, 168, 189, 216, 243, 252, 324, 378, 486, 504, 567, 648, 756, 972, 1134, 1512, 1701, 1944, 2268, 3402, 4536, 6804, 13608]
#3.Find the number digits in 1050! and how many zeros are there in 1050! F = factorial(1050) digits = F.ndigits() zeros = str(F).count("0") print("Number of digits:", digits) print("Number of zeros:", zeros)
Number of digits: 2719 Number of zeros: 472
#5.Evaluate the \int\frac{\cos(x)}{\sqrt{\sin(x)+1}}dx a=cos(x) b=sqrt(sin(x)+Integer(1)) f(x)=a/b f.integral(x)
x |--> 2*sqrt(sin(x) + 1)
#6.Find the fifth order derivative f=ln(x)+3*x^3*cos(2*x) f.diff(5)
-96*x^3*sin(2*x) + 720*x^2*cos(2*x) + 1440*x*sin(2*x) + 24/x^5 - 720*cos(2*x)
def invest(): amt=int(input("Enter the amount invested:")) yr=int(input("Enter the years of investment")) interest_amt=(amt*yr*4)/100 return(interest_amt)
invest()
Enter the amount invested:
Enter the years of investment
1000

What You Learn:

In this practical I learnt to use the basic mathematical functions of the sage math and utilize the advanced calculator for various functions.