Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168754
Image: ubuntu2004

Test sheet

This is where we compute something important ai=1a_i=1

x = [1,2,3,4,5,6] print x[2:] plot(sin,(-1,1))
[3, 4, 5, 6]
var('x y') density_plot(sin(x^2 + y^2) * cos(x+y^2) * sin(y), (x,-4, 4), (y,-4, 4), cmap='jet', plot_points=100).show(figsize=(6,6), frame=True)
stnc = 'I am a cool multiedge graph with loops' g = DiGraph({}, loops=True, multiedges=True) for a,b in [(stnc[i], stnc[i+1]) for i in xrange(len(stnc)-1)]: g.add_edge(a, b, b) g.plot(color_by_label=True, edge_style='solid').show(figsize=(8,8))
x0 = 0 f = sin(x)*e^(-x) p = plot(f,-1,5, thickness=2) dot = point((x0,f(x=x0)),pointsize=80,rgbcolor=(1,0,0)) ft = f.taylor(x,x0,5) pt = plot(ft,-1, 5, color='green', thickness=2) html('$f(x)\;=\;%s$'%latex(f)) html('$\hat{f}(x;%s)\;=\;%s+\mathcal{O}(x^{%s})$'%(x0,latex(ft),5+1)) show(dot + p + pt, ymin = -.5, ymax = 1)
f(x)\;=\;e^{\left(-x\right)} \sin\left(x\right)
\hat{f}(x;0)\;=\;-\frac{1}{30} \, x^{5} + \frac{1}{3} \, x^{3} - x^{2} + x+\mathcal{O}(x^{6})
var('x1 x2 w1 w2 b') model(x1, x2) = w1*x1 + w2*x2 + b data = [[1, 2, -1], [1, 4, -1], [2, 4, -1], [2, 1, 1], [5, 1, 1], [4, 2, 1]] fit = find_fit(data, model, solution_dict=True); print fit f(x1, x2) = model.subs(fit); pl6 = implicit_plot(f(x1, x2) == 0, (x1, 0, 5), (x2, 0, 5)) pl1 = list_plot([(x,y) for (x,y,z) in data if z == -1], rgbcolor='red') pl2 = list_plot([(x,y) for (x,y,z) in data if z == 1], rgbcolor ='blue') (pl1 + pl2 +pl6).show(xmin=0, xmax=5, ymin=0) pl3 = plot3d(f(x1, x2), (x1, 0, 5), (x2, 0, 5)) pl4 = list_plot([(x,y) for (x,y,z) in data if z == -1], rgbcolor='red') pl5 = list_plot([(x,y) for (x,y,z) in data if z == 1], rgbcolor='blue') (pl3+pl4+pl5).show(xmin=0, xmax=5)
sv = plot(lambda x : x, (x, 0, 5)) cl1 = plot(lambda x : x + 1, (x, 0, 5), linestyle='dashed') cl2 = plot(lambda x : x - 1, (x, 0, 5), linestyle='dashed') (sv+cl1+cl2+pl1+pl2).show(xmin=0, xmax=5)
from libsvm import * prob = svm_problem([1,-1],[[1,0,1],[-1,0,-1]]) param = svm_parameter(kernel_type = LINEAR, C=float(10)) m = svm_model(prob, param)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_36.py", line 9, in <module> exec compile(ur'open("___code___.py","w").write("# -*- coding: utf-8 -*-\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZnJvbSBsaWJzdm0gaW1wb3J0ICoKcHJvYiA9IHN2bV9wcm9ibGVtKFsxLC0xXSxbWzEsMCwxXSxbLTEsMCwtMV1dKQpwYXJhbSA9IHN2bV9wYXJhbWV0ZXIoa2VybmVsX3R5cGUgPSBMSU5FQVIsIEM9ZmxvYXQoMTApKQptID0gc3ZtX21vZGVsKHByb2IsIHBhcmFtKQ=="),globals())+"\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpokA7PK/___code___.py", line 3, in <module> from libsvm import * ImportError: No module named libsvm
from rpy2.robjects import * r(''' data = data.frame(x = c(1,1,2,2,5,4), y = c(2,4,4,1,1,2), cls = c(-1,-1,-1,1,1,1)) model = lm(cls ~ x + y, data=data) print(summary(model)) ''')
Call: lm(formula = cls ~ x + y, data = data) Residuals: 1 2 3 4 5 6 -0.6556 0.2111 -0.1148 0.5852 -0.3926 0.3667 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.1963 0.9478 0.207 0.849 x 0.3259 0.1966 1.658 0.196 y -0.4333 0.2365 -1.832 0.164 Residual standard error: 0.6106 on 3 degrees of freedom Multiple R-squared: 0.8136, Adjusted R-squared: 0.6893 F-statistic: 6.546 on 2 and 3 DF, p-value: 0.08049