viernes, 19 de abril de 2019

Trefethen's list of 13 classic papers in applied mathematics - Трефетен список 13 классических работ по прикладной математике

https://www.stat.uchicago.edu/~lekheng/courses/302/classics/

Trefethen's list of 13 classic papers in applied mathematics

Трефетен список 13 классических работ по прикладной математике

Origin of this list

Contents of this file:

  [1] Trefethen NA-net posting of 9 May 1993
  [2] bibliographic citations for 13 "classic papers"
  [3] longer list of papers we considered reading
  [4] copy of handout to class describing course organization
  [5] weekly assignments

These items are separated by dashed lines.

       -----------------------------------------------------------------
       |  Prof. L. N. Trefethen             Phone: (607) 255-4222      |
       |  Dept. of Computer Science           Fax:   "   255-4428      |
       |  Upson Hall, Cornell University                               |
       |  Ithaca, NY 14853-7501             Email: lnt@cs.cornell.edu  |
       -----------------------------------------------------------------


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[1] Trefethen NA-net posting of 9 May 1993


From: Nick Trefethen 
Date: Thu, 6 May 93 10:36:16 -0400
Subject: Classic Papers in Numerical Analysis

Tutorial para hacer A=QR por medio de Algoritmo de Householder - Tutorial to do A = QR by means of Householder Algorithm - Учебник, чтобы сделать A = QR с помощью алгоритма домохозяина

Tutorial en Octave para hacer A=QR por medio de Algoritmo de Householder

  Учебник, чтобы сделать A = QR с помощью алгоритма домохозяина

 Tutorial to do A = QR by means of Householder Algorithm

Autor: Alexander Arias

Fecha: 19 de abril de 2019

El método de Householder consiste en construir matrices unitariaselementales (reflexiones) que operan sucesivamente sobre las columnas de A para reducir esta matriz a una forma triangular superior.
https://www.inf.utfsm.cl/~parce/cc1/clase14-RP.html
http://www.ehu.eus/izaballa/Ana_Matr/Apuntes/lec7.pdf

Unitary Triangularization of a Nonsymmetric Matrix
https://www.stat.uchicago.edu/…/302/classics/householder.pdf


#***************************** *****************************
#A continuación empieza el código para Octave o matlab
#***************************** *****************************

disp("Tutorial para hacer A=Qr por medio de Algoritmo de Householder");
#Autor: Alexander Arias
#Fecha: 19 de abril de 2019
#Ejemplo de A=QR por medio de transformaciones de householder:
#Algunos items teóricos se tomarón de poujh:
#https://www.youtube.com/watch?v=oOHNgFtBFUo
#https://www.youtube.com/watch?v=6VTLJQ2v7So

#Obtener vectores base e:
#e = @(x) eye(size(A))(:,x);
#e(1)

disp('A=QR por medio de transformaciones de householder')
A=[2 1 2; 2 2 1; 1 2 2]
disp('-------------------------------------------------')
disp('Encontrar A2=H1*A')
a1=A(:,1)
e = eye(size(A))(:,1);
u=a1-norm(a1)*e
v=u/norm(u)
vvt=v*v'
E=eye(size(A));
H1=E-2*vvt
A2=H1*A

disp('-------------------------------------------------')
disp('Encontrar R=H2*A2')
A2p=A2(2:end,2:end)
a2p=A2p(:,1)
e = eye(size(A2p))(:,1)
u=a2p-norm(a2p)*e
v=u/norm(u)
vvt=v*v'
E=eye(size(A2p));
H2p=E-2*vvt
H2=eye(size(A));
H2(2:end,2:end)=H2p
disp('La R sin redondeo es:')
R=H2*A2

disp('-------------------------------------------------')
disp('Primera forma de redondeo con función round')
Rp=round(mymatrix .* 10000) ./ 10000

disp('-------------------------------------------------')
disp('Segunda forma de redondeo con archivos')

#Primero escribo la matriz en el archivo deseado con el formato que quiero
filename = "Householder_3x3_poujh.txt";
fid = fopen (filename, "a+");
fprintf(fid,"%4.4f %4.4f %4.4f\n", R);
fclose (fid);

#Luego la leo y la guardo en una segunda matriz
filename = "Householder_3x3_poujh.txt";
fid = fopen (filename, "r");
Rk=fscanf(fid,"%f",[3,3])
fclose (fid);

#Borrar el contenido completo de un archivo
#Lo abro con w y lo cierro
#filename = "Householder_3x3_poujh.txt";
#fid = fopen (filename, "w");
#fclose (fid);


disp('-------------------------------------------------')
disp('Encontramos Q=H1t * H2t');
Q=H1'*H2'
disp('-------------------------------------------------')
disp('Desplegamos A=QR calculado con el algoritmo de Householder paso a paso');
Q
Rk
disp('Rectificamos que el producto sea A=QR');
Q*Rk

disp('-------------------------------------------------')
disp('Ahora con el algoritmo de octave [Q,R]=qr(A)');
[Q,R]=qr(A)
disp('Rectificamos que el producto sea A=QR');
Q*R


#***************************** *****************************
#Aqui termina el código
#***************************** *****************************


#***************************** *****************************
#A continuación se muestra el resultado
#***************************** *****************************

octave:94> source("Householder_3x3_poujh.m")
Tutorial para hacer A=Qr por medio de Algoritmo de Householder
A=QR por medio de transformaciones de householder
A =

   2   1   2
   2   2   1
   1   2   2

-------------------------------------------------
Encontrar A2=H1*A
a1 =

   2
   2
   1

u =

  -1
   2
   1

v =

  -0.40825
   0.81650
   0.40825

vvt =

   0.16667  -0.33333  -0.16667
  -0.33333   0.66667   0.33333
  -0.16667   0.33333   0.16667

H1 =

   0.66667   0.66667   0.33333
   0.66667  -0.33333  -0.66667
   0.33333  -0.66667   0.66667

A2 =

   3.0000e+00   2.6667e+00   2.6667e+00
  -5.5511e-16  -1.3333e+00  -3.3333e-01
  -3.3307e-16   3.3333e-01   1.3333e+00

-------------------------------------------------
Encontrar R=H2*A2
A2p =

  -1.33333  -0.33333
   0.33333   1.33333

a2p =

  -1.33333
   0.33333

e =

Diagonal Matrix

   1
   0

u =

  -2.70770
   0.33333

v =

  -0.99251
   0.12218

vvt =

   0.985071  -0.121268
  -0.121268   0.014929

H2p =

  -0.97014   0.24254
   0.24254   0.97014

H2 =

   1.00000   0.00000   0.00000
   0.00000  -0.97014   0.24254
   0.00000   0.24254   0.97014

La R sin redondeo es:
R =

   3.0000e+00   2.6667e+00   2.6667e+00
   4.5776e-16   1.3744e+00   6.4676e-01
  -4.5776e-16  -1.6653e-16   1.2127e+00

-------------------------------------------------
Primera forma de redondeo con función round
Rp =

   3.00000   2.66670   2.66670
   0.00000   1.37440   0.64680
  -0.00000  -0.00000   1.21270

-------------------------------------------------
Segunda forma de redondeo con archivos
Rk =

   3.00000   2.66670   2.66670
   0.00000   1.37440   0.64680
  -0.00000  -0.00000   1.21270

-------------------------------------------------
Encontramos Q=H1t * H2t
Q =

   0.66667  -0.56592   0.48507
   0.66667   0.16169  -0.72761
   0.33333   0.80845   0.48507

-------------------------------------------------
Desplegamos A=QR calculado con el algoritmo de Householder paso a paso
Q =

   0.66667  -0.56592   0.48507
   0.66667   0.16169  -0.72761
   0.33333   0.80845   0.48507

Rk =

   3.00000   2.66670   2.66670
   0.00000   1.37440   0.64680
  -0.00000  -0.00000   1.21270

Rectificamos que el producto sea A=QR
ans =

   2.0000   1.0000   2.0000
   2.0000   2.0000   1.0000
   1.0000   2.0000   2.0001

-------------------------------------------------
Ahora con el algoritmo de octave [Q,R]=qr(A)
Q =

  -0.66667   0.56592   0.48507
  -0.66667  -0.16169  -0.72761
  -0.33333  -0.80845   0.48507

R =

  -3.00000  -2.66667  -2.66667
   0.00000  -1.37437  -0.64676
   0.00000   0.00000   1.21268

Rectificamos que el producto sea A=QR
ans =

   2.0000   1.0000   2.0000
   2.0000   2.0000   1.0000
   1.0000   2.0000   2.0000
 




























 


martes, 16 de abril de 2019

Como poner en mayuscula la primera letra de una cadena en Excel y el resto de la cadena quede como estaba How to capitalize the first letter of a string in Excel and the rest of the string is as it was Как сделать заглавной первую букву строки в Excel, а остальную часть строки, как это было

Como poner en mayuscula la primera letra de una cadena en Excel y el resto de la cadena quede como estaba

How to capitalize the first letter of a string in Excel and the rest of the string is as it was

Как сделать заглавной первую букву строки в Excel, а остальную часть строки, как это было
 

En este ejemplo suponemos que la celda con la cadena a convertir esta en la J209:

=MAYUSC(IZQUIERDA(J209;1))&DERECHA(J209;LARGO(J209)-1)


Si fuera la A1:
=MAYUSC(IZQUIERDA(A1;1))&DERECHA(A1;LARGO(A1)-1)

En Excel en Ingles:
=UPPER(LEFT(A1;1))&RIGHT(A1;LEN(JA1)-1)

viernes, 12 de abril de 2019

Complex Problems which can be solved in a line or two using python

https://itspythonand.blogspot.com/2019/04/complex-problems-which-can-be-solved-in.html?fbclid=IwAR2pEJ4dZUDc_qu5lbULRNNoXX40jQdTQ7ybpff1eRj1bZxX2mSpzx85XEo


Complex Problems which can be solved in a line or two using python

   

1.Removing duplicate elements from list or array

       Example:
           input [1,1,1,2,2,3,4,5,6,6,1]
          output  [1, 2, 3, 4, 5, 6]

we can convert the given list into set which will remove its duplicate elements and then again convert it back to the list.
>>> a=[1,1,1,2,2,3,4,5,6,6,1]
>>> list(set(a))
[1, 2, 3, 4, 5, 6]

     2.Using filter function to solve complex problem like extracting even numbers from list or a number greater than some number.

 We can use the filter method to to solve above problem.
The filter() method filters the given sequence with the help of a function that tests each element         in the sequence to be true or not.

Extracting numbers greater than another number such as 2

Example
Input:[1,2,3,4]
Output:[3,4]
>>> n=[1,2,3,4]
>>> print (list(filter(lambda x: x > 2, n)))
[3,4]

Extracting even numbers from a list

Example:
Input:[0,1,2,3,5,8,13]
Output:[0,2,8]
>>> n=[0,1,2,3,5,8,13]
>>> print (list(filter(lambda n: n % 2, seq) ))
    [0,2,8]

    3.Taking Transpose of a Matrix(Inverting it would be a dream)

Example:
Input:[[1,2,3],[4,5,6],[7,8,9]]
Output:[[1, 4, 7], [2, 5, 8], [3, 6, 9]] 
>>> n=[[1,2,3],[4,5,6],[7,8,9]]
>>> print ([list(i) for i in zip(*a)])
    [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

4.Common Strings from two lists

>>> P = {'Ann','Joe','Jill','Tim'}
>>> R= {'Ann','Vik','Nathan','Zack'}
>>> P & R
    {'Ann'}

5.Reading lines as list from files

>>> lines = [line.strip() for line in open('foo.txt')]

5. Some other common but important problems

Reversing a string

>>> n="itspythonand"
>>> n[::-1]
    andnothypsti

Swapping two variables

>>> a=10
>>> b=20
>>> a,b=b,a    #it swaps their values
we can intialize two variables like this also
>>> a,b=10,20

jueves, 11 de abril de 2019

solution of the second order ODE


http://fourier.eng.hmc.edu/e176/lectures/NM/node42.html

Example
Solve the famous 2nd order constant-coefficient ordinary differential equation
\begin{displaymath}
m\ddot{y}(t)+c\dot{y}(t)+k y(t)=f(t)
\end{displaymath}

with zero initial conditions $\ddot{y}(0)=\dot{y}(0)=0$. Here we assume $m=10$, $c=1$, and $k=10$, and a step input $y(t)=u(t)$. Find the numerical solution $y(t)$ from $t_0=0$ to $t_{final}=50$ in $N=1,000$ steps (step size $h=(t_{final}-t_0)/N$, using each of the following methods:
  • Euler's method
  • Modified Euler's method
  • Runge-Kutta 2
  • Runge-Kutta 4
The close-form solution of the second order ODE is:
\begin{displaymath}
y(t)=1-\frac{e^{-\zeta\omega_nt}}{\sqrt{1-\zeta^2}}\sin(\omega_dt+\phi)
\end{displaymath}

where
\begin{displaymath}\zeta=\frac{c}{2\sqrt{mk}},\;\;\;\;\;\;\;\;
\omega_n=\sqrt{\...
..._d=\omega_n \sqrt{1-\zeta^2},\;\;\;\;\;\;\phi=\cos^{-1}\zeta
\end{displaymath}

The results of these numerical integral methods and the ground truth closed-form solution are compared as shown below for three different step sizes: 0.5 (left), 0.05 (middle), and 0.01 (right): RungeKuttaExample.png

next up previous

QR Decomposition (Householder Method) calculator Matrix A Online Step by step


https://atozmath.com/MatrixEv.aspx?q=qrdecomphh&q1=13%2C5%2C2%2C2%3B3%2C11%2C6%2C6%3B2%2C2%2C8%2C4%3B2%2C2%2C4%2C8%60qrdecomphh%60D#tblSolution

13 5 2 2
3 11 6 6
2 2 8 4
2 2 4 8

Solution:
Here A = 

13522

31166

2284

2248


A1 = 

13522

31166

2284

2248


a1 = 

13

3

2

2


||a1||=√132+32+22+22=√186=13.6382

v1=a1-sign(a11)||a1||e1 = 

13

3

2

2
 - 13.6382 × 

1

0

0

0
 = 

-0.6382

3

2

2


H1=I-2⋅v1⋅vT1vT1⋅v1 = 

1000

0100

0010

0001
-217.4073⋅

-0.6382

3

2

2
⋅
[-0.6382322]
 = 

0.95320.220.14660.1466

0.22-0.0341-0.6894-0.6894

0.1466-0.68940.5404-0.4596

0.1466-0.6894-0.45960.5404


H1⋅A1 = 

0.95320.220.14660.1466

0.22-0.0341-0.6894-0.6894

0.1466-0.68940.5404-0.4596

0.1466-0.6894-0.45960.5404
 × 

13522

31166

2284

2248
 = 

13.63827.77234.9864.986

0-2.0322-8.0368-8.0368

0-6.6881-1.3578-5.3578

0-6.6881-5.3578-1.3578




Now removing 1st row and 1st column, we get
A2 = 

-2.0322-8.0368-8.0368

-6.6881-1.3578-5.3578

-6.6881-5.3578-1.3578


a2 = 

-2.0322

-6.6881

-6.6881


||a2||=√(-2.0322)2+(-6.6881)2+(-6.6881)2=√93.5914=9.6743

v2=a1-sign(a11)||a1||e1 = 

-2.0322

-6.6881

-6.6881
 + 9.6743 × 

1

0

0
 = 

-11.7064

-6.6881

-6.6881


H2=I-2⋅v1⋅vT1vT1⋅v1 = 

100

010

001
-2226.5023⋅

-11.7064

-6.6881

-6.6881
⋅
[-11.7064-6.6881-6.6881]
 = 

-0.2101-0.6913-0.6913

-0.69130.605-0.395

-0.6913-0.3950.605


H2⋅A2 = 

-0.2101-0.6913-0.6913

-0.69130.605-0.395

-0.6913-0.3950.605
 × 

-2.0322-8.0368-8.0368

-6.6881-1.3578-5.3578

-6.6881-5.3578-1.3578
 = 

9.67436.3316.331

06.85072.8507

02.85076.8507




Now removing 1st row and 1st column, we get
A3 = 

6.85072.8507

2.85076.8507


a3 = 

6.8507

2.8507


||a3||=√6.85072+2.85072=√55.0588=7.4202

v3=a1-sign(a11)||a1||e1 = 

6.8507

2.8507
 - 7.4202 × 

1

0
 = 

-0.5695

2.8507


H3=I-2⋅v1⋅vT1vT1⋅v1 = 

10

01
-28.4508⋅

-0.5695

2.8507
⋅
[-0.56952.8507]
 = 

0.92330.3842

0.3842-0.9233


H3⋅A3 = 

0.92330.3842

0.3842-0.9233
 × 

6.85072.8507

2.85076.8507
 = 

7.42025.2639

0-5.2298




Now removing 1st row and 1st column, we get


Since, H3H2H1A=R

H3H2H1A=

1000

0100

000.92330.3842

000.3842-0.9233
 × 

1000

0-0.2101-0.6913-0.6913

0-0.69130.605-0.395

0-0.6913-0.3950.605
 × 

0.95320.220.14660.1466

0.22-0.0341-0.6894-0.6894

0.1466-0.68940.5404-0.4596

0.1466-0.6894-0.45960.5404
 × 

13522

31166

2284

2248
 = 

13.63827.77234.9864.986

09.67436.3316.331

007.42025.2639

000-5.2298
 = R


Also A=H1H2H3R and A=QR, ∴Q=H1H2H3

Q=H1H2H3=

0.95320.220.14660.1466

0.22-0.0341-0.6894-0.6894

0.1466-0.68940.5404-0.4596

0.1466-0.6894-0.45960.5404
 × 

1000

0-0.2101-0.6913-0.6913

0-0.69130.605-0.395

0-0.6913-0.3950.605
 × 

1000

0100

000.92330.3842

000.3842-0.9233
 = 

0.9532-0.249-0.15860.0654

0.220.9603-0.15860.0654

0.14660.08890.90370.3922

0.14660.08890.3647-0.9152




checking Q×R=A?

Q×R = 

0.9532-0.249-0.15860.0654

0.220.9603-0.15860.0654

0.14660.08890.90370.3922

0.14660.08890.3647-0.9152
 × 

13.63827.77234.9864.986

09.67436.3316.331

007.42025.2639

000-5.2298
 = 

13522

31166

2284

2248


and A = 

13522

31166

2284

2248