Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
28 views
%html <h1> TP1 </h1>

TP1

s=1 f(x)=(1/(s*sqrt(2*pi)))*exp(-x**2/(2*s**2))
show(f)
x  2e(x22s2)2πs\displaystyle x \ {\mapsto}\ \frac{\sqrt{2} e^{\left(-\frac{x^{2}}{2 \, s^{2}}\right)}}{2 \, \sqrt{\pi} s}
F(x)=integrate(f,x,-infinity,x) show(F)
x  2(2πerf(122x)+2π)4π\displaystyle x \ {\mapsto}\ \frac{\sqrt{2} {\left(\sqrt{2} \sqrt{\pi} \text{erf}\left(\frac{1}{2} \, \sqrt{2} x\right) + \sqrt{2} \sqrt{\pi}\right)}}{4 \, \sqrt{\pi}}
plot(f(x),x,-10,10)
plot(F(x),x,-10,10)
m=2 f1(x)=f(x-m) plot(f1(x),x,-10,10)
solve(F(x)==1/2,x)
[x == 0]
solve(0.95==2*(F(x)-1/2),x)
[x == sqrt(2)*inverse_erf(19/20)]
%html <h1> TP2 Devoir Maison </h1>

TP2 Devoir Maison

erf
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 982, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "<string>", line 1 solve(erf ^ SyntaxError: unexpected EOF while parsing
erf?
File: /projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/functions/other.py Signature : erf(self, coerce=True, hold=False, dont_call_method_on_arg=False, *args) Docstring : The error function, defined for real values as erf(x) = frac{2}{sqrt{pi}} int_0^x e^{-t^2} dt. This function is also defined for complex values, via analytic continuation. EXAMPLES: We can evaluate numerically: sage: erf(2) erf(2) sage: erf(2).n() 0.995322265018953 sage: erf(2).n(100) 0.99532226501895273416206925637 sage: erf(ComplexField(100)(2+3j)) -20.829461427614568389103088452 + 8.6873182714701631444280787545*I Basic symbolic properties are handled by Sage and Maxima: sage: x = var("x") sage: diff(erf(x),x) 2*e^(-x^2)/sqrt(pi) sage: integrate(erf(x),x) x*erf(x) + e^(-x^2)/sqrt(pi) ALGORITHM: Sage implements numerical evaluation of the error function via the "erf()" function from mpmath. Symbolics are handled by Sage and Maxima. REFERENCES: * http://en.wikipedia.org/wiki/Error_function * http://mpmath.googlecode.com/svn/trunk/doc/build/functions/expin tegrals.html#error-functions
erf(100).n()
1.00000000000000
erf(2).n()
0.995322265018953
erf(1).n()
erf(1)
f(x)= (1/(1*sqrt(2*pi)))*exp(-x**2/(2*1**2)) plot(f)
#on cherche a tel que a=F^-1(1.95/2) ou F(x)=integrate(f,x,-infinity,x) f(x)= (1/(1*sqrt(2*pi)))*exp(-x**2/(2*1**2)) F(x)=integrate(f,x,-infinity,x) a=(1/F(1.95/2)) show(a)
22π2πerf(0.4875000000000002)+2π\displaystyle \frac{2 \, \sqrt{2} \sqrt{\pi}}{\sqrt{2} \sqrt{\pi} \text{erf}\left(0.487500000000000 \, \sqrt{2}\right) + \sqrt{2} \sqrt{\pi}}
erf(0.4875*sqrt(2)).n()
0.670439740039379
sqrt(2)
sqrt(2)
a.n(100)
1.1972895232681974325711429172
plot(F,-5,5)
plot(f,-5,5)
f(x)= (1/(1*sqrt(2*pi)))*exp(-x**2/(2*1**2)) %r f <- function(x) {(1/(1*sqrt(2*pi)))*exp(-x**2/(2*1**2))} F <- function(x) {integrate(f,lower=-Inf,upper=1)$value} Approx <- function(n){ x0 = 0 x1 = 4 f <- function(x) {(1/(1*sqrt(2*pi)))*exp(-x**2/(2*1**2))} F <- function(x) {integrate(f,lower=-Inf,upper=1)$value} a=1 while (x1-x0 > 10**-3 && a<=n ){ if ( F((x0+x1)/2) > 0 ){ x1=(x0+x1)/2 x0=x0 a=a+1 } if ( F((x0+x1)/2) < 0 ){ x0=(x0+x1)/2 x1=x1 a=a+1 } else{} } vec <- c(x0,x1) return(vec) } Approx(100)
  1. 0
  2. 0.0009765625
%r s=1 f <- function(x){(1/(s*sqrt(2*pi)))*exp(-x**2/(2*s**2))} F <- function(x){integrate(f,lower=-Inf,upper=1)$value} a = 0 b = 4 n=10 plot(F,-5,5) for (i in 1:n){ if ( F((a+b)/2) > 0 ){ b=(a+b)/2 } if ( F((a+b)/2) < 0 ){ a=(a+b)/2 } else{} } return(c(a,b))
Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab, : 'expr' did not evaluate to an object of length 'n' Traceback: 1. plot(F, -5, 5) 2. plot.function(F, -5, 5) 3. curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab, . ...) 4. stop("'expr' did not evaluate to an object of length 'n'")
s=1 f(x)=(1/(s*sqrt(2*pi)))*exp(-x**2/(2*s**2)) F(x)=integrate(f,x,-infinity,x) a = 0 b = 4 n=10 plot(F,-5,5) %r for (i in 1:n){ if ( F((a+b)/2) > 0 ){ b=(a+b)/2 print(b) } if ( F((a+b)/2) < 0 ){ a=(a+b)/2 print(a) } else{} } return(c(a,b))
[1] 2 [1] 1 [1] 0.5 [1] 0.25 [1] 0.125 [1] 0.0625 [1] 0.03125 [1] 0.015625 [1] 0.0078125 [1] 0.00390625
  1. 0
  2. 0.00390625