Sei sulla pagina 1di 19

Métodos numéricos

Tarea 1
1. Bisección: La suma de dos números es 20. Si cada uno se agrega a su raíz
cuadrada, el producto de las dos sumas es 155,55. Determine los dos números
con una exactitud de 10-4.

DESARROLLO EN MATLAB
This is the Bisection Method.
Input the function F(x) in terms of x
For example: cos(x)
((20-x)+(20-x)^(1/2))*(x+x^(1/2))-155.55
Input endpoints A < B on separate lines
5
10
Input tolerance
10^(-4)
Input maximum number of iterations - no decimal point
20
Select output destination
1. Screen
2. Text file
Enter 1 or 2
1
Select amount of output
1. Answer only
2. All intermediate approximations
Enter 1 or 2
2
Bisection Method
I P F(P)
1 7.50000000e+00 8.6316225e+00
2 6.25000000e+00 -2.7916316e+00
3 6.87500000e+00 3.5046467e+00
4 6.56250000e+00 5.0384069e-01
5 6.40625000e+00 -1.1068959e+00
6 6.48437500e+00 -2.9229948e-01
7 6.52343750e+00 1.0807501e-01
8 6.50390625e+00 -9.1535809e-02
9 6.51367188e+00 8.4136649e-03
10 6.50878906e+00 -4.1525051e-02
11 6.51123047e+00 -1.6546688e-02
12 6.51245117e+00 -4.0642605e-03
13 6.51306152e+00 2.1752649e-03
14 6.51275635e+00 -9.4435710e-04
15 6.51290894e+00 6.1548909e-04
16 6.51283264e+00 -1.6442521e-04

Approximate solution P = 6.51283264


with F(P) = -0.00016443
Number of iterations = 16 Tolerance = 1.00000000e-04

RESPUESTA: uno de los números es aproximadamente 6.51283264, y ambos


suman 20, el otro número es aproximadamente 13.48716736
2. Punto Fijo: Un objeto que cae verticalmente en el aire está sujeto a una
resistencia viscosa y también a la fuerza de gravedad. Suponga que dejamos caer
uno objeto de masa m desde una altura s0 y que la altura del objeto después de t
segundos es:

𝑚𝑔 𝑚2 𝑔 −𝑘𝑡
𝑠(𝑡) = 𝑠𝑜 − 𝑡 + 2 (1 − 𝑒 𝑚 )
𝑘 𝑘
𝑝𝑖𝑒𝑠 𝑙𝑏−𝑠
Donde 𝑔 = 32.17 y 𝑘 representa el coeficiente de resistencia del aire en
𝑠2 𝑝𝑖𝑒𝑠
𝑙𝑏−𝑠
Suponga que 𝑠𝑜 = 300 𝑝𝑖𝑒𝑠 y 𝑚 = 0.25 𝑙𝑏𝑠 y que 𝑘 = 0.1 . Calcule
𝑝𝑖𝑒𝑠
con una exactitud de 0.01 s, el tiempo que tarda este peso de cuarto de libra en
caer al suelo.

DESARROLLO EN MATLAB
This is the Fixed-Point Method.
Input the function G(x) in terms of x
For example: cos(x)
6.230183401-2.5*exp(-0.4*x)
Input initial approximation
1
Input tolerance
0.01
Input maximum number of iterations - no decimal point
20
Select output destination
1. Screen
2. Text file
Enter 1 or 2
1
Select amount of output
1. Answer only
2. All intermediate approximations
Enter 1 or 2
2
FIXED-POINT METHOD
I P
1 4.55438329e+00
2 5.82582861e+00
3 5.98702464e+00
4 6.00220836e+00
5 6.00358877e+00

Approximate solution P = 6.00358877


Number of iterations = 5 Tolerance = 1.00000000e-02

RESPUESTA: El tiempo que tarda el peso en caer es de 6.00358877 segundos


3. Newton y extensiones

DESARROLLO EN MATLAB
This is Newtons Method
Input the function F(x) in terms of x
For example: cos(x)
-(32.17/(2*x^2))*(((exp(x)-exp(-x))/2)-sin(x))-1.7 (Esta ecuación resulta de la suposición del enunciado)

Input the derivative of F(x) in terms of x


((32.17*(((exp(x)-exp(-x))/2)-sin(x)))/x^3)-((16.085*(((exp(x)+exp(-x))/2)-cos(x)))/x^2)
Input initial approximation
2
Input tolerance
10^(-5)
Input maximum number of iterations - no decimal point
10
Select output destination
1. Screen
2. Text file
Enter 1 or 2
1
Select amount of output
1. Answer only
2. All intermediate approximations
Enter 1 or 2
2
Newtons Method
I P F(P)
1 -1.49754292e-01 -8.9706692e-01
2 -3.17064999e-01 1.7286976e-05
3 -3.17061775e-01 2.3758773e-14

Approximate solution = -3.1706177453e-01


with F(P) = 2.3758772727e-14
Number of iterations = 3
Tolerance = 1.0000000000e-05

RESPUESTA: la tasa 𝒘 a la que cambia el angulo, es negativa como se indica en


las ecuaciones del enunciado del ejercicio, con un valor aproximado de
-3.1706177453e-01
4. Muller: Dos escaleras se cruzan en un pasillo de ancho 𝑊. Cada una llega de la
base de un muro a un punto en el muro de enfrente. Las escaleras se cruzan a
una altura H arriba del pavimento. Dado que las longitudes de las escaleras son
𝑥1 = 20 pies y 𝑥2 = 30 pies y que 𝐻 = 8 𝑝𝑖𝑒𝑠, calcule 𝑊.

DESARROLLO EN MATLAB
This is Mullers Method.
Input the Polynomial P(x)
For example: to input x^3-2*x+4 enter
[ 1 0 -2 4 ]
[1 -16 -500 8000 -32000]
Input tolerance
0.0001
Input maximum number of iterations - no decimal point
10
Input the first of three starting values
16
Input the second of three starting values
18
Input the third starting value
20
Select output destination
1. Screen
2. Text file
Enter 1 or 2
1
MULLERS METHOD
The output is i, approximation x(i), f(x(i))

The real and imaginary parts of x(i) are


followed by real and imaginary parts of f(x(i)).

3 27.993386 0.000000 63224.534703 0.000000


4 24.740018 0.000000 -7767.637704 0.000000
5 25.208302 0.000000 -556.607682 0.000000
6 25.241921 0.000000 -4.047697 0.000000
7 25.242167 0.000000 0.000352 0.000000
8 25.242167 0.000000 0.000000 0.000000

Method Succeeds
Approximation is within 1.0000000000e-04
in 8 iterations

RESPUESTA: El ancho del pasillo, nombrado como w corresponde a 25.242167


pies
3
5. Neville: Use la función 𝑓(𝑥) = 𝑒 𝑥 para aproximar a √𝑒 usando los puntos 0,1,
6
0.2, 0.3, 0.4, 0.5, 0.6, 0.7 y 0.8. Aproxime el mismo número usando la función √𝑥
, escoja los nodos apropiados para la aproximación y n = 6.

3
DESARROLLO EN MATLAB APROXIMANDO CON FUNCIÓN 𝑓(𝑥) = 𝑒 𝑥 A √𝑒
This is Nevilles Method.
Choice of input method:
1. Input entry by entry from keyboard
2. Input data from a text file
3. Generate data using a function F
Choose 1, 2, or 3 please
1
Input n
7
Input X(0) and F(X(0)) on separate lines.
0.1
1.105170918
Input X(1) and F(X(1)) on separate lines.
0.2
1.221402758
Input X(2) and F(X(2)) on separate lines.
0.3
1.349858808
Input X(3) and F(X(3)) on separate lines.
0.4
1.491824698
Input X(4) and F(X(4)) on separate lines.
0.5
1.648721271
Input X(5) and F(X(5)) on separate lines.
0.6
1.8221188
Input X(6) and F(X(6)) on separate lines.
0.7
2.013752707
Input X(7) and F(X(7)) on separate lines.
0.8
2.225540928
Input point at which the polynomial is to be evaluated
1.395612425
Select output destination
1. Screen
2. Text file
Enter 1 or 2
1
NEVILLES METHOD
Table for P evaluated at X = 1.39561242 , follows:
Entries are XX(I), Q(I,0), ..., Q(I,I) for each I = 0, ..., N where N = 7

0.10000000 1.10517092
0.20000000 1.22140276 2.61108508
0.30000000 1.34985881 2.75723925 3.55788090
0.40000000 1.49182470 2.90525474 3.64208502 3.92153393
0.50000000 1.64872127 3.05390647 3.71957818 3.95092429 4.01673022
0.60000000 1.82211880 3.20169109 3.78958745 3.97525495 4.02364939 4.03465936
0.70000000 2.01375271 3.34678197 3.85141710 3.99478200 4.02874015 4.03582254 4.03717109
0.80000000 2.22554093 3.48697789 3.90449002 4.00985966 4.03231077 4.03656417 4.03730037 4.03741038

3
RESPUESTA: El valor aproximado para √𝑒 es 4.03741038
6 3
DESARROLLO EN MATLAB APROXIMANDO CON FUNCIÓN 𝑓(𝑥) = √𝑥 A √𝑒 SE DESCARTA EL
PRIMER VALOR DE 0.1, TOMANDO 𝒏 = 𝟔 COMO LO INDICA EL ENUNCIADO
This is Nevilles Method.
Choice of input method:
1. Input entry by entry from keyboard
2. Input data from a text file
3. Generate data using a function F
Choose 1, 2, or 3 please
1
Input n
6
Input X(0) and F(X(0)) on separate lines.
0.2
0.7647244913
Input X(1) and F(X(1)) on separate lines.
0.3
0.818188823
Input X(2) and F(X(2)) on separate lines.
0.4
0.8583742189
Input X(3) and F(X(3)) on separate lines.
0.5
0.8908987181
Input X(4) and F(X(4)) on separate lines.
0.6
0.9183859022
Input X(5) and F(X(5)) on separate lines.
0.7
0.9422865815
Input X(6) and F(X(6)) on separate lines.
0.8
0.963492484
Input point at which the polynomial is to be evaluated
1.395612425
Select output destination
1. Screen
2. Text file
Enter 1 or 2
1
NEVILLES METHOD
Table for P evaluated at X = 1.39561242 , follows:
Entries are XX(I), Q(I,0), ..., Q(I,I) for each I = 0, ..., N where N = 6

0.20000000 0.76472449
0.30000000 0.81818882 1.40395068
0.40000000 0.85837422 1.25846501 0.53422831
0.50000000 0.89089872 1.18219217 0.84063766 1.75538441
0.60000000 0.91838590 1.13707735 0.95760780 1.26781745 0.29803161
0.70000000 0.94228658 1.10854268 1.00929729 1.12915015 0.88800341 1.70878683
0.80000000 0.96349248 1.08979747 1.03397310 1.08296381 1.01419093 1.16450864 0.62421054
3 6
RESPUESTA: El valor aproximado para √𝑒 es 0.62421054 con 𝑓(𝑥) = √𝑥
6. DIFERENCIAS DIVIDIDAS: La tabla siguiente contiene la población de Estados
Unidos en ciertos años desde 1930 a 1980.
Año 1930 1940 1950 1960 1970 1980
Población 157326 179323 207892 226500 249003 281522

Utilice diferencias divididas para aproximar la población en los años 1945, 1965y 1985.

DESARROLLO EN MATLAB
Newtons form of the interpolation polynomial
Choice of input method:
1. Input entry by entry from keyboard
2. Input data from a text file
3. Generate data using a function F
Choose 1, 2, or 3 please
1
Input n
5
Input X(0) and F(X(0)) on separate lines
1930
157326
Input X(1) and F(X(1)) on separate lines
1940
179323
Input X(2) and F(X(2)) on separate lines
1950
207892
Input X(3) and F(X(3)) on separate lines
1960
226500
Input X(4) and F(X(4)) on separate lines
1970
249003
Input X(5) and F(X(5)) on separate lines
1980
281522
Select output destination
1. Screen
2. Text file
Enter 1 or 2
1
NEWTONS INTERPOLATION POLYNOMIAL

Input data follows:


X(0) = 1930.00000000 F(X(0)) = 157326.00000000
X(1) = 1940.00000000 F(X(1)) = 179323.00000000
X(2) = 1950.00000000 F(X(2)) = 207892.00000000
X(3) = 1960.00000000 F(X(3)) = 226500.00000000
X(4) = 1970.00000000 F(X(4)) = 249003.00000000
X(5) = 1980.00000000 F(X(5)) = 281522.00000000

The coefficients Q(0,0), ..., Q(N,N) are:


157326.00000000
2199.70000000
32.86000000
-2.75550000
0.12662083
-0.00317700

RESPUESTA: El polinomio sería entonces


𝒑(𝒙) = 𝟏𝟓𝟕𝟑𝟐𝟔 + 𝟐𝟏𝟗𝟗. 𝟕(𝒙 − 𝟏𝟗𝟑𝟎) + 𝟑𝟐. 𝟖𝟔(𝒙 − 𝟏𝟗𝟑𝟎)(𝒙 − 𝟏𝟗𝟒𝟎) − 𝟐. 𝟕𝟓𝟓𝟓 (𝒙 −
𝟏𝟗𝟑𝟎)(𝒙 − 𝟏𝟗𝟒𝟎)(𝒙 − 𝟏𝟗𝟓𝟎) + 𝟎. 𝟏𝟐𝟔𝟔𝟐𝟎𝟖𝟑 (𝒙 − 𝟏𝟗𝟑𝟎)(𝒙 − 𝟏𝟗𝟒𝟎)(𝒙 − 𝟏𝟗𝟓𝟎)(𝒙 −
𝟏𝟗𝟔𝟎) − 𝟎. 𝟎𝟎𝟑𝟏𝟕𝟕𝟎𝟎(𝒙 − 𝟏𝟗𝟑𝟎)(𝒙 − 𝟏𝟗𝟒𝟎)(𝒙 − 𝟏𝟗𝟓𝟎)(𝒙 − 𝟏𝟗𝟔𝟎)(𝒙 − 𝟏𝟗𝟑𝟎)
Para determinar la población en los años 1945, 1965 y 1985, se reemplaza 𝒙 por
cada uno de estos valores para obtener así:
𝑿 = 𝟏𝟗𝟒𝟓 𝒑(𝒙) = 𝟏𝟗𝟒𝟗𝟕𝟖. 𝟑𝟐𝟎𝟑
𝑿 = 𝟏𝟗𝟔𝟓 𝒑(𝒙) = 𝟐𝟑𝟔𝟐𝟓𝟒. 𝟎𝟎𝟕𝟔
𝑿 = 𝟏𝟗𝟖𝟓 𝒑(𝒙) = 𝟐𝟗𝟏𝟗𝟓𝟑. 𝟏𝟖𝟖𝟏

7. Hermite: Un automóvil viaja por una carretera recta y su recorrido se cronometra


en varios puntos, los datos se incluyen en la tabla, donde el tiempo se indica en segundos
y la distancia en millas

Tiempo (s) 0 3 5 8 13
Distancia (mi) 0 225 383 623 993
Velocidad (mi/s) 75 77 80 74 72

Use el polinomio de Hermite para predecir la posición del automóvil en el instante


t = 10 segundos.

DESARROLLO EN MATLAB
This is Hermite interpolation.
Choice of input method:
1. Input entry by entry from keyboard
2. Input data from a text file
3. Generate data using a function F
Choose 1, 2, or 3 please
1
Input the number of data points minus 1
4
Input X(0), F(X(0)), and F'(X(0)) on separate lines
0
0
75
Input X(1), F(X(1)), and F'(X(1)) on separate lines
3
225
77
Input X(2), F(X(2)), and F'(X(2)) on separate lines
5
383
80
Input X(3), F(X(3)), and F'(X(3)) on separate lines
8
623
74
Input X(4), F(X(4)), and F'(X(4)) on separate lines
13
993
72
Choice of output method:
1. Output to screen
2. Output to text file
Please enter 1 or 2
1
HERMITE INTERPOLATING POLYNOMIAL

The input data follows:


X, F(X), F'(x)
0.0000000000e+00 0.0000000000e+00 7.5000000000e+01
3.0000000000e+00 2.2500000000e+02 7.7000000000e+01
5.0000000000e+00 3.8300000000e+02 8.0000000000e+01
8.0000000000e+00 6.2300000000e+02 7.4000000000e+01
1.3000000000e+01 9.9300000000e+02 7.2000000000e+01

The Coefficients of the Hermite Interpolation Polynomial


in order of increasing exponent follow:

0.0000000000e+00
7.5000000000e+01
0.0000000000e+00
2.2222222222e-01
-3.1111111111e-02
-6.4444444444e-03
2.2638888889e-03
-9.1319444444e-04
1.3052679158e-04
-2.0223631973e-05
Do you wish to evaluate this polynomial?
Enter Y or N
Y
Enter a point at which to evaluate
10
x-value and interpolated-value
1.0000000000e+01 7.4250283910e+02

RESPUESTA: Aproximadamente A los 10 segundos, la posición del automóvil es


742.50283910 millas, resultado que tiene sentido observando las posiciones en el
segundo 8 y en el segundo 13.
8. Spline cúbico sujeto: Mediante interpolantes de Spline cúbico sujeto, aproxime
la parte superior del perro que se muestra en la figura

Se debe hacer las aproximaciones para cada curva.


DESARROLLO EN MATLAB PARA LA CURVA 1
numero de datos=8
vector de abscisas=[1 2 5 6 7 8 10 13 17]
vector de ordenadas=[3 3.7 3.9 4.2 5.7 6.6 7.1 6.7 4.5]
segunda derivada al principio=1.0
segunda derivada al final=-0.67
GRAFICA RESULTANTE PARA LA APROXIMACIÓN DE LA CURVA 1

DESARROLLO EN MATLAB PARA LA CURVA 2


numero de datos=6
vector de abscisas=[17 20 23 24 25 27 27.7]
vector de ordenadas=[4.5 7.0 6.1 5.6 5.8 5.2 4.1]
segunda derivada al principio=3.0
segunda derivada al final=-4.0
GRAFICA RESULTANTE PARA LA APROXIMACIÓN DE LA CURVA 2

DESARROLLO EN MATLAB PARA LA CURVA 3


numero de datos=3
vector de abscisas=[27.7 28 29 30]
vector de ordenadas=[4.1 4.3 4.1 3.0]
segunda derivada al principio=0.33
segunda derivada al final=-1.5

ERROR (Index in position 2 is invalid. Array indices must be positive integers or logical values)

Potrebbero piacerti anche