Documentos de Académico
Documentos de Profesional
Documentos de Cultura
TRABAJO PROGRAMACIN EN
MATLAB
Trabajo 2
SOLUCIN:
Nota: el valor dado en la hoja est mal debido a que si se remplaza el x=0 la
ecuacin no cumple a diferencia de x=1 con este valor se ha trabajado
1
= (1 + ) 2
2
1
= (1 + ) 2
2
(1 + )
2
=
2
1 2 + 2
=
4
4
= +
2 + 2
4
1= +
2 + 12
C=7
La ecuacin ser:
4
= +1
2 + 2
La programacin en Matlab ser:
fun=input('f(x): ');
f = inline(fun);
x1 = input('X(i): ');
x2 = input('X(i+1): ');
n = input('Nmero de Orden: ');
h = abs(x2 - x1);
v1 = f(x1);
v2 = f(x2);
et = abs((v2 - v1)/v2 * 100);
X(1,:) = [0 v1 0 et];
for i=1:n
X(i+1,1) = i;
D = diff(fun,i);
d1=inline(D);
d=d1(x1);
v1= v1+(d*((h^i)/factorial(i)));
X(i+1,2) = v1;
et=abs(((v2-v1)/v2)*100);
X(i+1,4) = et;
ea = abs((X(i+1,2)-X(i,2))/X(i,2)*100);
X(i+1,3) = ea;
if ea <=10^(-1)
break
end
end
f(x): -4/(2*x+x^2)+7
X(i): 0.1
X(i+1): 0.2
Nmero de Orden: 3
X=
0 -12.0476 0 476.1905
1.0000 7.9070 165.6315 478.1623
2.0000 -12.0908 252.9122 478.2562
3.0000 7.9091 165.4140 478.2606
Evaluando entre los valores de 0.2 a 0.3
f(x): -4/(2*x+x^2)+7
X(i): 0.2
X(i+1): 0.3
Nmero de Orden: 3
X=
0 -2.0909 0 273.8226
1.0000 2.8678 237.1542 138.4049
2.0000 0.3696 87.1103 69.2703
3.0000 1.6196 338.1375 34.6382
f(x): -4/(2*x+x^2)+7
X(i): 0.3
X(i+1): 0.4
Nmero de Orden: 3
X=
0 1.2029 0 57.5448
1.0000 3.3873 181.5959 19.5522
2.0000 2.6482 21.8196 6.5335
3.0000 2.8951 9.3211 2.1785
f(x): -4/(2*x+x^2)+7
X(i): 0.4
X(i+1): 0.5
Nmero de Orden: 3
X=
0 2.8333 0 25.4386
1.0000 4.0486 42.8922 6.5424
2.0000 3.7376 7.6830 1.6432
3.0000 3.8156 2.0887 0.4111
2. Realice un programa para el mtodo de runge kutta de orden 2; luego
aproxima la solucin del problema de valor inicial usando su
programa,donde
NOTA: use n=10, para escoger el paso h:
= + + 1, 0 1
(0) = 1
SOLUCION:
function f
fprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES
POR MEDIO RUNGE-KUTTA DE ORDEN 2\n')
f=input('\n Ingrese la ecuacion diferencial dy/dx=\n','s');
x0=input('\n Ingrese el primer punto x0:\n');
x1=input('\n Ingrese el segundo punto x1:\n');
y0=input('\n Ingrese la condicion inicial y(x0):\n');
n=input('\n Ingrese el numero de pasos n:\n');
h=(x1-x0)/n;
xs=x0:h:x1;
fprintf('\n''it x0 y(x1)');
for i=1:n
it=i-1;
x0=xs(i);
x=x0;
y=y0;
k1=h*eval(f);
x=xs(i+1);
y=y0+k1;
k2=h*eval(f);
y0=y0+(k1+k2)/2;
fprintf('\n%2.0f%10.6f%10.6f\n',it,x0,y0);
end
fprintf('\n El punto aproximado y(x1) es = %8.6f\n',y0);
Resultado del problema pedido resolucin de ecuaciones diferenciales
por medio runge-kutta de orden 2
'it x0 y(x1)
0 0.000000 1.005000
1 0.100000 1.019025
2 0.200000 1.041218
3 0.300000 1.070802
4 0.400000 1.107076
5 0.500000 1.149404
6 0.600000 1.197210
7 0.700000 1.249975
8 0.800000 1.307228
9 0.900000 1.368541
" + () = [ . ] () = . () =
SOLUCION:
function f
fprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO
METODO DE EULER\n')
f=input('\nIngrese la ecuacion diferencial de la forma: dy/dx=f(x,y)\n','s');
x0=input('\nIngrese el primer punto x0:\n');
x1=input('\nIngrese el segundo punto x1:\n');
y0=input('\nIngrese la condicion inicial y(x0):\n');
n=input('\nIngrese el numero de pasos n:\n');
h=(x1-x0)/n;
xs=x0:h:x1;
y1=y0;
fprintf('\n''it x0 x1 y1');
for i=1:n
it=i-1;
x0=xs(i);
x=x0;
x1=xs(i+1);
y=y0;
y1=y0+h*eval(f);
fprintf('\n%2.0f%10.6f%10.6f%10.6f\n',it,x0,x1,y1);
y0=y1;
end
fprintf('\n El punto aproximado y(x1) es = %10.6f\n',y1);
" + () = [ . ] () = . () =
= 10sin()
1
=
10 sin()
1
=
10
1
( ) + =
10 2
sin(2)
=
10cos(2)
'it x0 x1 y1
2 2 sin()
" = ( ) + ( 2 ) +
2
(1) = 1
(2) = 2
= 0.2
SOLUCIN:
function bvp_ej
clc,clear,clf
disp(' Este programa resuelve la siguiente E.D.O de segundo
orden')
disp(' con valores en la frontera : ')
disp('-----------------------------------------------------
-------')
disp(' dy/dx + x*dy/dx + y = 3x^2+2 ')
disp(' y(0)= 0 y(1)=1 ')
disp('-----------------------------------------------------
-------')
options= bvpset('stats','on');
solinit = bvpinit(linspace(0,1,2),[0.1 0]);
sol = bvp4c(@Dec,@trbc,solinit,options);
fprintf('\n');
fprintf('Las condiciones limites son y(0) = %7.5f y(1)')
%7.5f\n',sol.y(1,1),sol.y(1,end);
fprintf('\n')
disp( ' x y ' )
% Escriba el nmero de datos espaciados de x
n=11;
%figure
xint = linspace(0,1,n);
Sxint = deval(sol,xint);
plot(xint,Sxint(1,:));
title('Solucion de una E.D.O de segundo orden con valores
en las fronteras');
xlabel('X');ylabel('Y');
disp([xint;Sxint(1,:)]')
% ---------------------------------------------------------
---------------------
% Funciones anidadas
% La ecuacin es y'' + xy' + y = 3x^2 + 2 y(0)=0 y(1)=1
function dydx = Dec(x,y)
dydx = [y(2);3*x^2 - y(1) - x*y(2) + 2];
end
function res = trbc(ya,yb)
res = [ya(1);yb(1)-1];
end
end
la resolucion del ejercicio sera:
utilizando el agoritmo para aproximar la funcion al problema lineal con el valor
de frontera
2 2 sin()
" = ( ) + ( 2 ) +
2
(1) = 1
(2) = 2
= 0.2
( ) | ( )|