Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 5213
reset
<function reset at 0x7fc3ec6bb050>
#Getting help #with specific command: type the command name, append the question mark. E like solve? #Example #solve? var('x') solve(x^2+3*x-4==0,x)
x [x == 1, x == -4]
#Help for specific topic #Example #search_doc("numerical approximation")
# SageMath as a calculator 15*0.7^3
5.14500000000000
32^15
37778931862957161709568
#Exact and approximate returns sqrt(8);sqrt(8.0); N(sqrt(8))
2*sqrt(2) 2.82842712474619 2.82842712474619
38/46
19/23
pi; N(pi);pi.n(digits=20)
pi 3.14159265358979 3.1415926535897932385
#Exercise 1 (ws) Evaluate the number e with 15 decimal digits e;N(e);e.n(digits=15)
e 2.71828182845905 2.71828182845905
#Demo2:Functions and expressions #Pre-defined functions N(log(100));log(100,10);val=log(100.,2)
4.60517018598809 2
val;2^val
6.64385618977472 100.000000000000
#Exercise 2 (ws) (a)Evaluate three built-in functions of your choice for inputs of your choice. # (b) Explain why SageMath refuses to give the result for exp(3) and force it to evaluate the function approximately. exp(3.0)
20.0855369231877
#Simple user defined functions f(x)=x^2-3*x+4; f(3)
4
#expr=sin(x)+x^2;expr(1.1); You will see error message. Get used to this. Learn by practicing.
#Demo3: Basic plotting p=plot(f(x),-2,2,figsize=[4,2],color="lightblue",thickness=3)# Experiment with optional inputs (figsize, thickness, color) #See http://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html for more on 2D plotting
#Saving a plot in a file: #give a plot a name (say, p ) and type the command p.save('[file name].png')
#Exercise 3 (ws) #Remove the pound sign before the command "parametric_plot", and create a parametric plot using the command (choose your favorite color and specify the size of the plot). #Save the plot in a file with name 'my_first_plot.png' parametric_plot((cos(x),sin(x)^3),(x,0,2*pi),color="blue",figsize=[5,3 ],thickness=3)
#Declearing variables var('a b c')
(a, b, c)
#Solving equations exactly solve(x^2+b*x-5==0,x)
[x == -1/2*b - 1/2*sqrt(b^2 + 20), x == -1/2*b + 1/2*sqrt(b^2 + 20)]
#find_root?
t=var('t') #Finding roots approximately find_root(cos(t)-t,0,pi)
0.7390851332151607
# Syntax of user defined function syntax def char_fcn01(x): if x<=0 or x>=1: return 0 else: return 1
char_fcn01(0.5);char_fcn(1.5)
1
#Exercise 4. Define a function that finds the minimal element of the list. Test your function on example of your choice. ︠0079d924-025e-4f27-ae82-6b9bb11e2a68︠ #Exercise 5. Experiment with commands in the file sage-quickref-BasicMath.pdf. Include two examples using commands of your choice. Your commands should be different from arithmetic operations and the commands used in this worksheet. ︠8110ea0c-7702-4fc5-86ff-66c95f868d4b︠