Tarea 2
Tarea 2
a) x3 − 2x2 − 5 = 0, [1,4
Comandos de grafica.
b) x3 + 3x2 − 1 = 0, [−3,−2]
Comandos de grafica.
% Demo: Ecuacion no lineal
clc
disp('Demo: Solucion de una ecuacion no lineal')
disp('========================================')
x = -3:0.1:-2;
y = x.^3+3*x.^2-1;
plot(x,y)
Grafica.
Grafica.
2. By hand. Use Newton’s method to find solutions accurate to within 10−4 for the
following problems
a) ex + 2−x + 2cosx − 6 = 0, [1,2]
Comandos de grafica.
Grafica.
RESUSLTADOS DE COMANDOS
Demo: Método de Newton
======================
x0 = 12.900
er = 1.0000e-03
imax = 10
Fun =
FunDer =
a) Using the bisection method. Start with a = 0 and b = 1, and carry out the
first three iterations.
b) Using the secant method. Start with the two points, x1 = 0 and x2 = 1, and
carry out the first three iterations.
c) Using Newton’s method. Star at x1 = 1 and carry out the first three
iterations.
5. By hand. The lateral surface area, S, of a cone is given by: where
r is the radius of the base and h is the height. Determine the radius of a cone
that has a surface area of 1800 m2 and a height of 25 m. Solve by using
Newton’s method with
where g = 9.8m/s2. For a skydiver with drag coefficient c = 15kg/s, find the
mass m so that the speed is v = 35 m/s in t = 9 s. Use Newton’s method to
determine the mass m with a tolerance of ε = 10−5.
% DEMO: Método de Newton
% Input:
% Fun : Función defina la ecuación
% Funder : derivada de la función ecuación
% m0 : estimación inicial de la solución
% em : error máximo permitido
% imax : número máximo de iteraciones permitidas
% Output:
% ms : solución aproximada
clc
disp ('Demo: Método de Newton')
disp ('======================')
% Input:
m0 = 15
er = 10^(-5)
imax = 15
Fun = @(m) ((9.8.*m.*(1.-exp(-135./m)))-525)
FunDer = @(m) ((49*(1.-exp(-135./m)))/5)-((1323.*exp(-135./m))/m)
% print
disp(' iter sol er ')
disp('=====================================')
% main
for i = 1:imax
m = m0 - (Fun(m0))/FunDer(m0);
e = abs((m - m0)/m0);
fprintf('% 3i %11.6f %11.6f\n', i, m, e)
if e < er
ms = m0;
break
end
m0 = m;
end
fprintf('\n\n raiz -----> %11.6f\n', ms)
RESUSLTADOS DE COMANDOS
Demo: Método de Newton
======================
m0 = 15
er = 1.0000e-05
imax = 15
Fun =
FunDer =
@(m) ((49 * (1. - exp (-135 ./ m))) / 5) - ((1323 .* exp (-135 ./ m)) / m)
iter sol er
=====================================
1 53.620942 2.574729
2 59.588829 0.111298
3 59.840615 0.004225
4 59.841045 0.000007
Comandos de grafica.
% Demo: Ecuacion no lineal
clc
disp('Demo: Solucion de una ecuacion no lineal')
disp('========================================')
x = 10:0.1:15;
y = ((9.8.*x.*(1.-exp(-135./x)))-525);
plot(x,y)
Grafica.
RESUSLTADOS DE COMANDOS
%Demo: Método de Newton
======================
x0 = 4.5200
er = 1.0000e-04
imax = 10
Fun =
FunDer =
iter sol er
=====================================
1 -1.055328 1.233480
2 -1.003686 0.048934
3 -1.000019 0.003654
4 -1.000000 0.000019
raiz -----> -1.000019
Comandos de grafica.
7.B)
% DEMO: Método de Newton
% Input:
% Fun : Función defina la ecuación
% Funder : derivada de la función ecuación
% x0 : estimación inicial de la solución
% er : error máximo permitido
% imax : número máximo de iteraciones permitidas
% Output:
% xs : solución aproximada
clc
disp ('Demo: Método de Newton')
disp ('======================')
% Input:
x0 = 4.54
er = 10^(-4)
imax = 10
Fun = @(x) 0.5*x.^3 - 4*x.^2 - 5.5*x - 1
FunDer = @(x) 1.5*x.^2 - 8*x - 5.5
% print
disp(' iter sol er ')
disp('=====================================')
% main
for i = 1:imax
x = x0 - Fun(x0)/FunDer(x0);
e = abs((x - x0)/x0);
fprintf('% 3i %11.6f %11.6f\n', i, x, e)
if e < er
xs = x0;
break
end
x0 = x;
end
fprintf('\n\n raiz -----> %11.6f\n', xs)
RESUSLTADOS DE COMANDOS
Demo: Método de Newton
======================
x0 = 4.5400
er = 1.0000e-04
imax = 10
Fun =
@(x) 0.5 * x .^ 3 - 4 * x .^ 2 - 5.5 * x - 1
FunDer =
iter sol er
=====================================
1 -1.112603 1.245067
2 -1.013535 0.089041
3 -1.000243 0.013114
4 -1.000000 0.000243
5 -1.000000 0.000000
(a) Newton-Raphson
% DEMO: Método de Newton
% Input:
% Fun : Función defina la ecuación
% Funder : derivada de la función ecuación
% x0 : estimación inicial de la solución
% em : error máximo permitido
% imax : número máximo de iteraciones permitidas
% Output:
% ms : solución aproximada
clc
disp ('Demo: Método de Newton')
disp ('======================')
% Input:
x0 = 2
er = 10^(-5)
imax = 15
Fun = @(x) 2.*sin(sqrt(x))-x
FunDer = @(x) (cos(sqrt(x))/sqrt(x))-1
% print
disp(' iter sol er ')
disp('=====================================')
% main
for i = 1:imax
x = x0 - (Fun(x0))/FunDer(x0);
e = abs((x - x0)/x0);
fprintf('% 3i %11.6f %11.6f\n', i, x, e)
if e < er
xs = x0;
break
end
x0 = x;
end
fprintf('\n\n raiz -----> %11.6f\n', xs)
RESUSLTADOS DE COMANDOS
Demo: Método de Newton
======================
x0 = 2
er = 1.0000e-05
imax = 15
Fun =
FunDer =
iter sol er
=====================================
1 1.972499 0.013750
2 1.972381 0.000060
3 1.972381 0.000000
(b) Secant.
% DEMO: Método de Secante
% Input:
% Fun : Función defina la ecuación
% xa, xb : estimación inicial de la solución
% er : error máximo permitido
% imax : número máximo de iteraciones permitidas
% Output:
% xs : solución aproximada
clc
disp ('Demo: Método de Secante')
disp ('======================')
% Input:
xa = -2
xb = 2
er = 10^(-5)
imax = 10
Fun = @(x) 2.*sin(sqrt(x))-x
% print
disp(' iter sol er ')
disp('=====================================')
% main
for i = 1:imax
x = xb - (Fun(xb)*(xb - xa)/(Fun(xb) - Fun(xa)));
e = abs((x - xb)/xb);
fprintf('% 3i %11.6f %11.6f\n', i, x, e)
if e < er
xs = x;
break
end
xa = xb;
xb = x ;
end
fprintf('\n\n raiz -----> %11.6f\n', xs)
RESUSLTADOS DE COMANDOS
Demo: Método de Secante
======================
xa = -2
xb = 2
er = 1.0000e-05
imax = 10
Fun =
@(x) 2 .* sin (sqrt (x)) - x
iter sol er
=====================================
1 1.989613 0.011204
2 1.972456 0.013157
3 1.972381 0.000057
4 1.972381 0.000000
Comandos de grafica.
% Demo: Ecuacion no lineal
clc
disp('Demo: Solucion de una ecuacion no lineal')
disp('========================================')
x = -2:0.1:2;
y = 2.*sin(sqrt(x))-x;
plot(x,y)
Grafica.
using the Newton-Raphson method. Use the initial values of (a) x = 1.2 and y
= 1.2
RESUSLTADOS DE COMANDOS
======================
x0 = 1.2000
er = 1.0000e-04
imax = 15
iter sol er
=====================================
1 1.396364 0.163636
2 1.356041 0.028877
3 1.353945 0.001546
4 1.353939 0.000004
raiz -----> 1.353945
Comandos de grafica.
Grafica.
10. M-File. The equation
has a root between 15 and 20. Apply the Newton-Raphson method to find the
root with a tolerance of 10−5 and initial condition of x0 = 16.15.
RESUSLTADOS DE COMANDOS
Demo: Método de Newton
======================
x0 = 16.150
er = 1.0000e-05
imax = 15
Fun =
FunDer =
iter sol er
=====================================
1 9.077102 0.437950
2 -4.021010 1.442984
3 -1.676451 0.583077
4 -0.280396 0.832744
5 0.334244 2.192042
6 0.463023 0.385286
7 0.468470 0.011764
8 0.468480 0.000020
9 0.468480 0.000000
Comandos de grafica.
11. M-File. Suppose the reader is designing a spherical water storage tank for a
small town in a developing city. The volume of the liquid that it can contain
is calculated with
% Input:
% Output:
% xs : solución aproximada
clc
disp ('======================')
% Input:
h0 = 3
er = 10^(-4)
imax = 10
disp('=====================================')
% main
for i = 1:imax
h = h0 - Fun(h0)/FunDer(h0);
e = abs((h - h0)/h0);
if e < er
xs = h0;
break
end
h0 = h;
end
RESUSLTADOS DE COMANDOS
Demo: Método de Newton
======================
h0 = 3
er = 1.0000e-04
imax = 10
Fun =
FunDer =
iter sol er
=====================================
1 2.061033 0.312989
2 2.027042 0.016492
3 2.026906 0.000067