Академический Документы
Профессиональный Документы
Культура Документы
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
%.............................................................
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)
( (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:
Generate a table of values like the one shown and generate a graph with the data in the table.