Вы находитесь на странице: 1из 12

List No.

9
Problems proposed in the course of differential equations
Mechanical Engineering

1. M-File. Use the Newton method to solve the nonlinear equations, x0 is the starting point.
Algorithm:

Programa en MATLAB
% METODO DE NEWTON RAPHSON
clear all
clc
syms x
%.............................................................
% Ingrese la funcion f(x)
cf = input('Ingrese la funcion f(x) = ');
ezplot(cf)
grid on
title('GRAFICA DE LA FUNCION');xlabel('EJE X');ylabel('EJE Y')
x0 = input('Aproximacion Inicial x0 = ');
f = inline(cf); % funcion en linea
derivada = diff(cf,x);
df = inline(derivada);
tol = 10^(-6); % Tolerancia de Aproximacion
%.............................................................

ALGORITMO DE NEWTON – RAPHSON

x = x0;
n = 0;
error = 1;
disp(' (i) x(i) er(i)')
disp('============================================')
while(error > tol)
fprintf('\t%i \t%10.8f \t %10.8f\n', n, x, error)
n = n + 1;
a = x;
x = x - f(x)/df(x);
b = x;
error = abs(a-b);
end
hold on
plot(double(x), 0 , 'r*','Linewidth', 5)

a) 4 cos x = ex, x0 = 1, sol = 0.90478821789


Ingrese la funcion f(x) = exp(x)-4*cos(x)
Aproximacion Inicial x0 = 1
(i) x(i) er(i)
============================================
0 1.00000000 1.00000000
1 0.90843895 0.09156105
2 0.90479406 0.00364489
3 0.90478822 0.00000584

b) −0.9x2 + 1.7x + 2.5 = 0, x0 = 5, sol = 2.86010440551

Ingrese la funcion f(x) = -0.9^2+1.7*x+2.5


Aproximacion Inicial x0 = 5
(i) x(i) er(i)
============================================
0 5.00000000 1.00000000
1 -0.99411765 5.99411765
c) 3x = 2 − ex + x2, x0 = 0, sol = 0. 257530208544

Ingrese la funcion f(x) = 2-exp(x)+x^2-3*x


Aproximacion Inicial x0 = 0
(i) x(i) er(i)
============================================
0 0.00000000 1.00000000
1 0.25000000 0.25000000
2 0.25752495 0.00752495
3 0.25753029 0.00000534
d ) 3x2 = ex, x0 = 1, sol = 0.91000757249
Ingrese la funcion f(x) = exp(x)-3*x^2
Aproximacion Inicial x0 = 1
(i) x(i) er(i)
============================================
0 1.00000000 1.00000000
1 0.91415528 0.08584472
2 0.91001767 0.00413762
3 0.91000757 0.00001009

d) ex + 2−x + 5 cos x − 6 = 0, x0 = 2, sol = 1.82938360193

Ingrese la funcion f(x) = exp(x)+2^(-x)+5*cos(x)-6


Aproximacion Inicial x0 = 2
(i) x(i) er(i)
============================================
0 2.00000000 1.00000000
1 2.16546699 0.16546699
2 2.13371965 0.03174734
3 2.13229311 0.00142654
4 2.13229029 0.00000282
f ) x3 − x − 1 = 0, x0 = 1, sol = 1.32471995724

Ingrese la funcion f(x) = x^3-x-1


Aproximacion Inicial x0 = 1
(i) x(i) er(i)
============================================
0 1.00000000 1.00000000
1 1.50000000 0.50000000
2 1.34782609 0.15217391
3 1.32520040 0.02262569
4 1.32471817 0.00048222

g ) x3 − 2x2 − 5 = 0, x0 = 2.5, sol = 2.69064744803


Ingrese la funcion f(x) = x^3-2*x^2-5
Aproximacion Inicial x0 = 2.5
(i) x(i) er(i)
============================================
0 2.50000000 1.00000000
1 2.71428571 0.21428571
2 2.69095152 0.02333420
3 2.69064750 0.00030402
h) x − 0.8 − 0.2 sin x = 0, x0 = 1, sol = 0.90478821789
Ingrese la funcion f(x) = x-.8-.2*sin(x)
Aproximacion Inicial x0 = 1
(i) x(i) er(i)
============================================
0 1.00000000 1.00000000
1 0.96445297 0.03554703
2 0.96433389 0.00011908
Generate a table of values like the one shown and generate a graph with the data in the table.

( (xi) |xi −
i xi+1|
)
1 0.5000000 0.500000
2 0.5837483 0.005256
3 0.5989232 0.009265
4 0.6849232 0.000045
5 0.6925689 0.000001

2. M-File. Use the secant method to solve the nonlinear equations, x0 and x1 are the starting
point. Algorithm:

a) x3 − 2x2 − 5 = 0, x0 = 1 y x1 = 4, sol = 2.69064744788


Ingrese la funcion f(x) = x^3-2*x^2-5
Aproximacion Inicial x0 = 3
(i) x(i) er(i)
============================================
0 3.00000000 1.00000000
1 2.73333333 0.26666667
2 2.69162473 0.04170861
3 2.69064798 0.00097675

b) x3 + 3x2 − 1 = 0, x0 = −4 y x1 = 0, sol = -0.65270634440


Ingrese la funcion f(x) = x^3+3*x^2-1
Aproximacion Inicial x0 = -1
(i) x(i) er(i)
============================================
0 -1.00000000 1.00000000
1 -0.66666667 0.33333333
2 -0.65277778 0.01388889
3 -0.65270365 0.00007413

c) x − cos x = 0, x0 = 0 y x1 = π/2, sol = -0.73908513303


Ingrese la funcion f(x) = x-cos(x)
Aproximacion Inicial x0 = pi/4

(i) x(i) er(i)


============================================
0 0.78539816 1.00000000
1 0.73953613 0.04586203
2 0.73908518 0.00045096

d ) x − 0.8 − 0.2 sin x = 0, x0 = 0 y x1 = π/2, sol = 0.96433388455


Ingrese la funcion f(x) = x-0.8-0.2*sin(x)
Aproximacion Inicial x0 = pi/8

(i) x(i) er(i)


============================================
0 0.39269908 1.00000000
1 0.98620166 0.59350258
2 0.96437850 0.02182317
3 0.96433389 0.00004461
e) x3 − 6x2 + 11x − 6.1 = 0, x0 = 0 y x1 = 1, sol = 0.17898888342

Generate a table of values like the one shown and generate a graph with the data in the table.

(i) (xi) |xi −


xi+1|
1 0.5000000 0.500000
2 0.5837483 0.005256
3 0.5989232 0.009265
4 0.6849232 0.000045
5 0.6925689 0.000001

Ingrese la funcion f(x) = x^3-6*x^2+11*x-6.1


Aproximacion Inicial x0 = 0.5
(i) x(i) er(i)
============================================
0 0.50000000 1.00000000
1 0.84347826 0.34347826
2 1.00625154 0.16277328
3 1.05089312 0.04464158
4 1.05433076 0.00343764
5 1.05435073 0.00001997

Вам также может понравиться