Está en la página 1de 26

“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC

CÁLCULO NUMÉRICO

MÉTODOS NUMÉRICOS EN MATLAB

OBJETIVO:

El alumno será capáz de utilizar la computadora para la solución de


problemas matemáticos, utilizando el programa de MATLAB.

Los Métodos Numéricos son técnicas algorítmicas basadas en


operaciones aritméticas simples para la solución de problemas
matemáticos. Podríamos decir, en general, que:

Métodos Numéricos = Matemáticas + Computación


Ec No lrle
oles lnter..-.,ia,c,on y R0<7e"""1 lnto,¡roaon ��• Ec Dt«eno.>les

" U N I VE R S I D A D NACIONAL JORGE BASADRE G R D H M A N N"

FACULTAD DE INGENIERÍA

MÉTODOS N U M ÉRI C O S

Hecho Por:

Morco Sumor1 Tcllcz 07-31083


SALIR
Eli1vot1 Catunto Momoru 07•310xx

1
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

I. MÉTODO DE LA BISECCIÓN

M�TDDD BISECCIÓN

INGRESE LA FUNCION . �'


- ------·-•
_ c_o_,_1
_ ,_, _-_,_._,_._,_+_3_•_,_-_, ..

x cos(x)-2 x2+3 x-1


Ingrese los valores de :
. . .

o i · · · · · · · · · · j · · · · · · · · · · -' · · · · · · · · · · · '
A= ._ o_.,__--'

.
21) ; ••••••••••••••••• ------------------------------- -------------

B= .._
l __o_.,___,.

E= 0.01

J
-60 i

Raiz = •�---º-·-'_9_3_7_5 �
-ID ;

CÓDIGO DEL PROGRAMA

104 - f=get(handles.editl,'string' ) ;

105 - :f=inllne ( :f ) ;

106 - a = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 2 , ' s t r i n g ' ) ) ;

107 - b • � t r 2 d o ub l e ( g e t ( h a n d l e � . e d i t 3 , ' � t r 1 n g ' ) ) ;

108 - E = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 4 , ' s t r i n g ' ) ) ;

109

110 - 1.:f t. (a) *t. (b) < O

111 - while M� (b-a) >E

11 2 - x=(a+b)/2;

113 - if f (a) itf ( x ) ==O

114 - a=b;

115 - else

116 if f (a) *f ( X ) <0

117 - b=x;

118 - else

119 - a=x;

120 - end

121 - end

122 - set ( h a n d l e s . e d i t. 5 , ' 5 t t" 1. n g ' , x ) ;

123

124 - end

125 - e ree

126 - s e t ( h a n d l e s . e d 1 t S , ' s t r 1. n g ' , 'No exisce la ra1z en el incervalo');

127 - end

2
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

CÓDIGO DEL GRÁFICO

135 f=qet(handles.editl,'string');

136 f•inline ( f ) ;

137 ezplot(f), grid on

II. MÉTODO DE NEWTON-RAPHSON

NEWTON-RAPHSON

INGRESAR LA FUNCION: L
! x
_ •
_ 3
+_2
_ •
_ x
_ •
_ 2
_ +
_ 1
_ o
_ •
_ x
_ -
_ 2
0 _.

INGRESE LA DERIVADA 1 3*x"2+4*x+10

DE LA FUNCION: L.--------------------'

Ingrese los valores de:

m
Xo 1
= 1

lOO

E 0.001

Raiz =
1 . 36881

························�············�············
' ' '

' '

.
,

CÓDIGO DEL PROGRAMA

105 f•get(handle�.editl,'string' ) ;

106 g "" g e t ( h a n d l e � . e d i t 2 , • � t r i n g ' ) ;

107 f • i n ll n e ( f ) ;

108 g "" i n l i n e ( g ) ;

109 x = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 3 , ' s t r i n g ' ) l ;

110 E = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 4 , ' s t r i n g ' ) l ;

1 11

112 xl=x-f(x)/g(x);

113

114 Yhile abs (xl-x)>E

115 x=xl;I

116 x l = x - f ( X ) /g ( X ) ;

117 end

118 �et(handles.editS, 'str1ng' , x l ) ;

3
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

CÓDIGO DEL GRÁFICO

125 t•oet(bandle:,.editl, ' :, t r i n <;¡ ' ) ;

126 t•inllne(t);

127 eaplot(t), \ITid on

4
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

III. MÉTODO DE LA SECANTE

M �TODO SECANTE

INGRESE LA FUNCION : �l x
_ •
_ ,
_ •
_ 2
_ •
_ x
_ •
_ 2
_ +
_ 10
_ •
_ x
_ -
_ ,
_ , �

Ingrese los valores de :

ID

Xo= o

ID

1
X1=
,.


0.001
E= o

Raiz Aprox.= 1,36881


.ioo
. .
. .
. .
. .
. .
. .

.
,o .; • • • • • • • • • • • • ,• • • • • • • • • • • • • , • • • • • • • • • • • • • ¡.

►iM
. .

iiiii ¡;;;.;;;;
.,
o 6
• '

CÓDIGO DEL PROGRAMA

116 f • 1 n l i n e ( g e t ( h a n d l e .!! . e d 1 t l , ' s t r i n g ' ) l ;

117 xü=at.r z doua Ie (get (bend Iee . e d i t. 2 , ' � t r 1 n g ' ) ) ;

118 x l • � t r 2 d o ub l e (get (bend Iee . e d i t 3 , '�tring'));

119 E•5tr2double ( g e t ( h a n d l e .!1 . e: d i t 'l , ' .!l t r i n g ' ) ) ;

120

121 while abs ( X l - x O ) >E

122 x2=x1-( ( (x1-x0) *f ( x l ) ) / ( f ( x l ) - f ( x O ) ) ) ;

123 xo=x1;

124 X 1=x2;

125 end

126 set(handles.edit5,'string',x2)

CÓDIGO DEL GRÁFICO

134 f=get(handles.ed1tl, ' s t r 1 n g ' J ;

135 f•inline ( f ) ;

136 e2plot(f), grid on

5
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

IV. MÉTODO DE BAIRSTOWN

M�TDDD DE BAIRSTDWN

INGRESE COEFICIENTES ..._ __,

Error
Pe

---- Respuesta:

.. X1 ,
� -, X2

CÓDIGO DEL PROGRAMA

6
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

197 a•st.r2num(get. (b,.n<lln.e<l1t.l, 'st.r1nQ"' 1 1 ;

198 p•st.r2<1ou1>1<0 (ge<. 1 n,.n<11u . e<11t.2 , ' nr ing-' 1 1 ;

199 crsu2<1ou1>le (get I ban<11u . e<11t.3 , ' st.r 1ng-' 1 1 ;

200 t•nr2doul>le (get 11:1an<1lu. ed1t4, 'nr1ng' 1 1 ;

201 n•lengtb(a);

202 for l< • n : - 1 : 1

203 b(n+l)•O;

204 - b(n+2)•0;

205 b ti<) •a ti<) -p •t, 11<+1) -q•b 11<+2 1 ;

206 eo<I

207 tor 1•n:-l:l

208 c:(n+l)•O;

209 e (n-+2) •O;

210 r; ( i ) - b ( i ) - p • c l i-+ 1 ) - c¡ • b l i-+ 2 ) ;

2U end

212 P•(b(l) • c ( 1 ) - b ( 2 ) •e 13 1 1 / le 121 •e 111 - le 131 l '21;

213 - O-(b(2) • c: ( 2 ) - b l l ) •e 13 1 1 / le 121 •e 111 - le 131 l '21;

211 - •hile P>l ! O>l

215 p-p-+P;

216 c¡-c¡-+();

217 tor l< • n : - 1 : l

218 b (X) •a (X) -p •1> 1 X-+ l 1 -q•i, l)<-+2 1 ;

219 b(n+l)•O;

220 b(n+2)•0;

221 end

tor ••n:-1: l

223 ,; (1) •b (1) -p•c 11-+11 -q•b 11+2 I ;

224 - ,;(n+l)•O;

225 c(n+2)•0;

226 end

227 P• (b(l) • c ( 4 ) - b l < ) •e 13 1 1 / le 1<1 •e 141 - ( c ( J I ¡ •;¡;

228 Q■ (b(2) •c ( 2 ) -b l1 ) •e 13 1 1 / le 1<1 •e 111 - ( c ( J I 1 ' < l ;

229 end

230 - p-p+P;

231 c¡-c¡-+Q;

232 - xl•(-p-+,,qrt.(p'2-4'q))/2;

233 - x2•(-p-,,qrt(p'2-4'c¡))/2;

234 - ""t.(bandle,,.ed>t5, '"tnnq' , x i ) ;

235 - ""t.(bandle,,.ed>t6, '"trinq' , x 2 ) ;

V. POLINOMIOS DE INTERPOLACIÓN DE LAGRANGE

7
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

P O L I N O M I O DE lA G R A N G E
Ingrese los puntos :

lngrHe l
a l'unclon :

Ingrese valor a lnt.rpolar :

1 1

Valor lnt.rpolado es

1 1

Calcular
(fi,:UII'

CÓDIGO DEL PROGRAMA

98 x•str2num(get(handles.edit1, ' s t r i n g ' ) ) ;

99 n•length(x);

100 :Cl•get (handles. ed1 t2, 'str 1nq' ) ;

101 t • 1 n li n e ( :C l ) ;

102 xx•str2double (qet (handles.edit3, 'str1nq'));

103 s•O;

"'
10S toe k•l:n

106 NU111•l;

107 Dl!n•l;

108 toi: 1•1:n

109 1:C k -•1;

110 Num-Num• ( ><X-X ( i) ) ;

111 Den•Den•(x(k)-x(1));

112 end

113 La•Nwn/Den;

114 - end

115 ::,•s+La•t (x ( k ) ) ;

116 end

11 7 ""t ( hand les . edlt.4 , ' suc i ng" , ") ;

8
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

VI. REGRESIÓN LINEAL

R E G R E S I Ó N LI N E A L

LAECUACION DE LA RECTA E S : y•-12 .50 00 00 +6.5500 00 x

111 '°

"'
20
IMFII
-

,o +

►-EN .,o

'

CÓDIGO DEL PROGRAMA


1 1
92 - x=smn�(get ( h a n d l e s . e d i t l , string ) ) ;

93 - v = s t r 2 n urn ( g e t ( h a n d l e s . e d i t 2 , 'string'));

94 - n•length ( x ) ;

95 - All=O; A12=0; A22=n; Bl=O; B2=0;

96

97 - for i•l:n

98 - A11=A11+x(i)"2;

99 - A12=A12+x ( i ) ;

100 - A2 l • A 1 2 ;

101 - Bl=Bl+x(i) 1t y ( i ) ;

102 - B2•B2+y(i);

103 - end

104 - a = ( B l 1t A 2 2 - B 2 1t A 1 2 ) / ( A l 1 1t A 2 2 - A 2 1 • A 1 2 ) ;

105 - b=(BZ*A11-B1*A21)/(A11*A22-A21*A12);

106 - cadena=sprintf('y=%8.6f+%8.6fx',b,a);

107 - set(handle�.edit3, 'string',cadena);

CÓDIGO DE LA GRÁFICA

9
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

114 - x = s t r 2 __n um ( g e t ( h a n d l e s . e d 1 t l , ' s t r i n g ' ) ) ;

115 y = � � 2 n wn ( g e t ( h a n d l e s . e d i t 2 , 'string')l;

116 n•length(x);

117 A ll • O ; A12•0; A22•n; B1•0; B 2 • 0;

118

119 far i=l:n

120 A ll = A ll + x ( i ) " 2 ;

121 A12•A12+x ( i ) ;

122 A2 l = A 1 2 ;

123 Bl =Bl+x ( 1 ) w y ( i ) ;

124 - B2=B2+y ( 1) ;

125 end

126 a ª ( B 1 .,,. A 2 2 - B 2 .,,. A 1 2 ) / ( A l l • A 2 2 - A 2 1 • A 1 2 ) ;

127 b= (B2 •A11-BPA2 l) / ( A 1 P A 2 2 - A 2 P A 1 2 ) ;

128

129 X X "' ( m i n ( x ) - 1 ) :0. 2: ( ma x ( x ) + l ) ;

130 yy•a. •xx+b;

131 p l o t ( x , y , ' • • ,xx,yy)

VII. REGRESIÓN POLINOMIAL

R E G R E S I Ó N P □LIN□MIAL
Ingrese los puntos :

X= 11·1 2 . 1 3 . 1 4 .3

Y=

__
_2.2 4.4 9.2 16. 8

Grado del pollnomlo : --;:::::::,

1. 6 3 9 7 -0.6177 0.96645
Coenclentes del polinomio•

"1EG"1ESION é'OLINOMLAL.

uiil

º,'-�,�,-�,--�,�,---,�-.,,,,�--c---,s,
Coordenadas X

CÓDIGO DEL PROGRAMA

10
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

122 - ,;¡lob"I " x y

123 - .a•suzn..., (,;¡et (ha.ndle:,. ed,t 1, ' str u,,;¡• l 1 ;

124 - r�(,;¡et (lt&ndles.ed,t.2,' stru1,;¡' 1 1 ;

125 - -len,;¡tb(¡<);lt-i'to del vector x

126 - n•:,trZ OUIO (,;¡et ( lt&ndle:,. edltJ, ' str u1,;¡' ) J ; lqraclo ele l po l rnom,o

127 - tor )•l:o+I

128 - tor l<•l:n+I

129 - sl•O:

130 - tor 1 • 1 , ,.

13 1 - s l • :, l + ( K ( l ) " (l + l< - 2 ) ) :

132 - end

133 - A ( ) , l< ) • :, 1 :

134 - end

135 - end

136 - tor 3•1:n+1

137 - :,2•0:

138 - for 1•1,,.

139 - e2•e2+ (y( 1) • (K ( 1) • (l - 1 ) ) ) :

·� -
141 -

·� - ·"'
B•B•:
·� -
a•,rw(l) •B:
·� -
145 -

set (handles.ed1t,, ' e t r i nq • , num2str (a) 1 ;

·� -
147 - gl®al !. .!\ f

CÓDIGO DE LA GRÁFICA

155 "•tl1plr l a ) ; \\carmlia de orden

156 b•min(x):O.la•K(K);l intervalo para el qrat,co del pol1nom10

p•polyval (a,b);

'" plot (K, ¡,, ' o r ' , b, p) ,Qrid on

'" xlabel('Coonienacl,._,, X');

'"
160 - ¡,!abe! ( ' Coorclenacla:, Y'),

161 - title (' RlGRlSION POLINOIIUL' 1 ;

VIII. MÉTODO DE GAUSS-JORDAN

11
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

G A U S S JDRDAN
Ingrese los coencreotes de la matriz A.

y los coeúoentes de la Matriz B

Calcular


Lu RafcH son:

-----------------·

CÓDIGO DEL PROGRAMA

86 A • � t � 2 n wn ( g e t ( h a n d l e :i . e ct 1 t l , ' :i t r 1 n g ' ) ) ;

87

88 [ m , n ] • s 1 :.: e ( A ) ;

89 for 1•1 :m

90 d i v i :i o r • A ( 1 , 1 ) ;

91 for J•i:n

92 A ( i, j) •A ( i, j ) /divi:ior;

end

"
94 tor k•l:m

95 lf 1-•k

96 pivote • A(k, 1 ) ;

97 for j•1:n

98 Ajk,j)•A(k,J)- pavoce .. A ( l , J ) ;

99 end

100 end

101 end

102 end

103

104 far 1•1 :m

105 x(1)•A(1,n):

106 enct

107

108 cadena•' ' ;

109 for t•l :m

UO cad•:iprlntf ( ' x:Cd•:C 6 . 2 t ' , t, x ( t ) ) ;

111 "-e.dene.•[ce.ctena;cad);

112 enct

113 ee c t nenc i ee ved ruz , ' :i t r 1 n g ' ,ce.ctenei);

12
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

IX. MÉTODO DE GAUSS-SEIDEL

GAUSS S E I D E L

Numero de Iteraciones Valores Iniciales

1 1
Matriz de Coeficientes Termine Independiente


"'

r.
c.

Las Iteraciones Son·

CÓDIGO DEL PROGRAMA

13
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

rn, !'MX1t.,•stt2double (,;¡H lhandl"". "d1tl,' !I U ut ,;¡ ' ) ) ;

v•stt2num(q,,t (b,.ndl"". "d1t2, 'strrn¡r' 1 1 ;

'"' et•str2 num (q,,t (b,.ndl"" . "d1U, '!1Uin11' 1 1 ;

'"' b•str2m1111(q,,t (b,.ndl"". edit�, '!1Uin11' 1 1 ;


'º'
ice [n,n]•sUe(a):

ics

uo cadl•''.

,u 1<•1:-•1te

u, '°' 1 • 1: n
'º'
u, X ( l ) -V ( I) ;

u, •oo
u, 1•!: D
'º'
u, s•O;

u; j•l:n
'º'
u, 1--,
u, " """-1-1> (1, j) •x (j) ;

HO •oo

•oo
'"
u, v( 1) • (
b (i) -,s) /,i (1, 1);

u, x(l)•V(1):

u,
'º'
t•l:n

"' 'º'
cad.2•apr1ntft••�d•�10.ef , 10 , x ( t l ¡,
"' ca<11•(cad1,cact2J,
"' .. ,
"' cacl2 •spr, ntt (.'..lll.:,, t) ;

"' cacll•(cadl,cad.2];

"'
'"
u, '°'
u, ""t( b"ndl"". o,ditS, ' !ltnnq' , cadl) ;

X. MÉTODO DE NEWTON

14
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

XI. REGLA DEL TRAPECIO

REGLA D E L T R A P E C I O

Ingresar la Funcion :

Ingrese el valor de 'a' l


:
.._ _.
09

08

Ingrese el valor de 'b' .._


� _.

Ingresa al valor de 'n' :��------�

El valor aprox.

lnit#ffii .............

CÓDIGO DEL PROGRAMA

116 - !•inl1ne(get(handles.ed1tl,'str1ng')):

117 - a • s t r 2 n wn ( g e t ( h a n d l e s . e d i t 2 , 'string'));

118 - b • s t r 2 n wn ( g e t ( h a n d l e s . e d i t 3 , 'string'));

119 - n • s t r 2 d o ub l e ( g e t ( h a n d l e s . e d 1 t i , ' s t r 1 n g ' ) ) ;

120 - h• (b-a) /n:

121 - s•t (a) +t (b);

122 - tor i•Z:n

123 - X ( l ) '" a + ( l - 1 ) *h;

124 - s•iH2*!(X(l));

125 - end

126 - I•s"(h/2);

1
127 - set(handles.editS, 'str1ng ,I);

CÓDIGO DE LA GRÁFICA

15
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

131 tunc::tion varargou,; • pu:,hbuttonS_Callbac::lt(h, event_data, handle:,, vararginl

132 .1'•1nline (get (Mndle:,. editl, ':,tr 1ng' ) ) ;

133 a•:,FrZnum(get (handle:,. ed1tZ, ':,tr1n11' ) ) ;

134 - b•=itrZnum(,;ret (handle:,. ed1t3, '=itr1ni;i' ) ) ;

135 n•:,trZdouble (,;ret (handle=i.echt4, ' =i t r 1 n ,;r ' ) ) ;

136 h• (b-a) /n;

137 .l'or 1•1:n+l

138 x(i)•a+(i-1) •h;

139 y ( i ) • .l' ( x ( i ) J ;

140 end

141 K • [ x , b , ,. , a ] :

142 7 • [ y , O , O , .l' ( a ) J ;

143 1'1 ll ( x , 7 , [ 0 . 6 0.6 0.9])

144 - ter 1•1:n+l

145 x(1)•a+(1-l) 'h;

146 y ( í ) • .l' ( x ( í ) ) ;

147 end

148 ho ld on

149 e;plot (.I', [lllill (Kl : O. Z : max (X) J 1

150 plot(x,7,'og')

151 plot(x,7,'g')

XII. REGLA DE SIMPSON 1/3

REGLA SIMPS □ N □E UN TERCI □


Ingrese l
a Funcion:

Ingrese el valor de 'a':I

Ingrese el valor de 'b':'

Ingrese el valor de 'n':'

Area aprox.: ._
l _.

l,wiffii

CÓDIGO DEL PROGRAMA

105 !•inline(get. (hl!l.ndle!l.edit.1, ' !l t. i: i n o ' ) ) ;

106 l!l.ª!lt.i::2doub le (get. ( he.ndle:,. edi t.2, ' ee r ing' ) ) ;

107 b•=it.r2double (get (he.ndle=i.edit.3, ' =i t r 1 n g • ) ) ;

108 n•!ltr2:double rcee (he.ndle!l.ed1t4, ' !l t. r 1 n g • ) ) :

109 h• (b-e.) /n;

110 !or i•l:n+l

111 X ( l. ) • e. + ( i - l) • h ;

112: end

113 1.! r e m ( n , 2: ) • • 0

114 !!•O;

115 !or i • J : 2 : n+l

116 =i::,+f (X ( i - 2: ) ) +4•! (X ( 1 - 1 ) ) +! (X (1))

117 ene

118 I .::, ( h /3 ) • !1

119 eec ( he.ndle!I. edi t.S, ' !lt.rin,;¡' , I) ;

12:0 end

16
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

CÓDIGO DE LA GRÁFICA

125 - :f • 1 n l i n e ( ,;r e t ( h 11 n d l e s . e d 1 t l , ' s t r 1 n 9 ' ) ) ;

126 - 11•str2double (Qet tnencnee .ecn cz • ' s t r i n Q ' ) ) ;

127 - b•:,tr2double (,;J!!t (h11ndl!!s.ed1t3, 'str1n9'));

128 - n•str2double (Qet (h11ndles.edit'I, ' s t r i n ,;r ' ) ) ;

129 - h• (b-ll) /n;

130 - s•:f (11) +:f (b) ;

131 - :for 1•1:n+l

132 - � ( 1 ) • 11 + ( ( 1 - 1 ) .- h ) ;

133 - y ( i ) • :f ( X ( i ) ) ;

134 - !!nd

135 - x • [ x , b , 11 , 11 ] ;

136 - y • ( y , 0 , 0 , :f ( ll ) ] ;

137- :fi ll ( x , y , [ 0 . 8 O . 'I 0.9])

138 - :for 1•1:n+l

139 - x ( 1 ) • 11 + ( ( 1 - 1 ) .- h ) ;

140 - y ( 1 ) • :f ( X ( l ) ) ;

141- l 1n e ( [ x ( 1 ) , x ( 1 ) l, [ O , :f ( x ( 1 ) ) ] ) ;

142 - !!nd

143 - holct on

144 - ezplot ( :f , [min ( x ) :O .2 :m11x ( x ) J )

XIII. REGLA DE SIMPSON 3/8


1
Un1i11ed·�

REGLA DE SIMPSDN D E 3/8

lng•- 11 funclon :

lng,_ 11 ,..,10, d1 ·•·: ,

lng,_ 11 ,..,10, d• ,,. :

1 "
lng,- 11 ,..,10, d• -.,
- :

1 "'
Ana aprox.

1 "'
02

00,--c �-c e c,-�e�-ce--c


0 2 0 0 6 0 8

CÓDIGO DEL PROGRAMA

17
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

117 t•rnlrne (,;¡et (handle,,.editl,' "trini;r' ) )

118 ,..,,tr2double (,;¡,et (Mndle" .ed1t2, '"trini;r' ) )

119 b•,,tr2double (,;¡,et (lu>.ndle" .ediU, '"trini;r' ) )

120 n•,,tr2double (,;¡,et (Mndle" .ed1ti, '"trini;r' ) )

121 h! (b-") /n

122 tor 1•1:n-tl

123 x ( 1 ) • ,. + ( i - l ) ' h

124 end

125 it rem(n,3)••0

126 ,,-o

127 tor i•3:n+l:3

128 ,,.,,H (x ( 1-2)) +3't (x ( i-1) ) +3 •t (x ( i) ) H (x I i-1))

129 end

130 I• ( (3'h) /B) '";

131 "et (hoondle,,.edit5,' "trini;r' , I)

132 end

CÓDIGO DE LA GRÁFICA

141 t•inllne (qH lh,.ndles. e<litl,' n r i n q • ) )

142 ,..,,tr2doub le ( ,;¡et ( h"nctle". ediU , ' "tr 1 n,;¡' ) )

143 b•,,tr2doub le ¡ ,;¡


et ( h"nctle". ed1t3 , ' "tr 1 n,;¡' 1 )

144 n•,,tr2doub le Iget. ( h"nctle". ed1t.i, ' ""r 1 n,;¡' 1 1

l4S h• (b-a) /n,

146 s•t¡a)+f(bl

147 tor i • l : n +l

148 x ( 1 ) • ,. + ( ( 1 - l ) ' h )

.14
9 y ( 1 ) • t ( x l i )) ;

ISO ene!

lSI x•[x,b,a,a]

152 Y![Y,0,0,t(a)J

153 ti ll ( x , y , { 0 . 6 O.B 0 . -1 ] )

154 tor 1 • ! : n +l

lSS x(1)•a+lli-l)'hl

lS6 y(1)•t(xli)):

lS7 li n e ( [ X ( i l , x l 1 ) ] , ( 0 , f ( X ( 1 ) ) ] )

158 en<I

159 hold on

160 e•plot. (t, {min (x) :O. 2 '""'" (x) J J ;

XIV. INTEGRALES MÚLTIPLES

18
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

I N T E G R A C I Ó N M Ú L T I P L E

Ingrese F(x,y)

Ingrese G1

Ingrese G2

Ingrese Valor de A

Ingrese 1alor B

Respuesta ¼mx1mada

'

1 05

03

JiJta&tJI IG®i&JI 02

o,

ºo 02 06 08

CÓDIGO DEL PROGRAMA

219 - t•inline (get ( nencnee , eda t l , ' :, t r 1ng' ) , ' x ' , ' y ' ) ;

220 - gl•inline (get ( nencnee , eda t 2 , ' :, t r 1ng' ) ) ;

221- g 2 • i n l i n e ( g e t ( h a n d l e :, . e d 1 t 3 , ' :, t r 1 n g ' ) ) ;

222 - a•:,tr2double (get ( h a n d l e s . e d i t 4 , ' s t r 1 n g ' l l ;

223 - b•str2double (get ( h a n d l e s . e d i t S , ' s t r i n 'iJ ' ) ) ;

224 - h• (b-a) / 2 ;

225 - xO•a;

226 - .;_•O;

227 - tor i•l:3

228 - h2•(g2 ( x O ) - g l ( x O ) ) / 2 ;

229 - 1" ( 1 ) • ( h 2/ 3 ) '"" ( :f ( ( x O ) , gl ( x O ) J +4 '" :f ( x O , gl (xO) +h2) +::f (x □, g2 ( x □)));


230 - x0•x0+h;

231 - end

232- I • ( h / J ) :r ( lJ ( l ) + 'P tJ ( 2 ) + w ( 3 ) ) ;

233- :, e t ( h a n d l e :, . e ct 1 t 6 , ' :, t r 1 n g ' , I ) ;

CÓDIGO DE LA GRÁFICA

245 f = g e t ( h a n ct l e s . e d i t l , ' s t r i n g ' ) ;

1 1
246 f l = i n l i n e ( f , ' x ' , y ) ;

247 ezmesh(fl);

248 grid on

19
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

XV. MÉTODO DE EULER

1
k�n•l:S.

M � T □ D □ DE EULER

lng�H E.O.O ftx.J) :

lng�H Valor Xo :

08

lng�H Valor Yo :

06

Num. Subintenr. :

lng�H Valor Final : °'


02

RHultldo Y :
c.
ºo 02 06 08

°'
lmt#iiffii [M.-tJIIA Graficar f(x, y)

CÓDIGO DEL PROGRAMA

117 f1=get(handles.edit1,'string'); f = 1. n l i n e ( f l , ' x ' , ' V ' ) ;

118 x O = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d 1 t 2 , ' s t r i n g ' ) ) ;

119 y O = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 3 , ' s t r i n g ' J J ;

120 n • s t r 2 d o ub l e ( g e t ( h a n d l e s . e d 1 t 4 , ' s t r i n g ' J J ;

121 b = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 5 , ' s t r i n g ' ) ) ;

122 h= (b-xO) /n;

123 for i=1: n

124 yO•yO+h•f(xO,yO);

125 xO=xO+h;

126 end

127 set(handles.edit6,'string',y0);

CÓDIGO DEL GRÁFICO

20
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

132 t i•(J"t. ( h,.n,ues . e<11 t. l, ' st.r 1n¡¡' ) ;

in t • , n l i ne ( t l , ' x ' , ' 'I' ' ) ;

134 e,....sh(tl;

135 gr l<I on

21
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

XVI. MÉTODO DE RUNGE KUTTA

- .

R U N G E -KUTTA DE 4ta O R D E N

Ingrese Funclon f(x,y) : 1 1

Ingrese•:
�==--------'
1

Ingrese b :
=======
1

=======
Nul
mng
ere
rosd
eeVS
al
uob
rlnte
lnlc.Yo
rv. n:: l
••-•••-------­

Soluclon Aprox. 1 02

ii·fr#fü.ii 1,,4;;;;.;;

CÓDIGO DEL PROGRAMA

110 - fl•get(handles.editl,'string');

1
111 - ñ=a nf í.ne ( f l , ' x ' , y ' ) ;

112 - a = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d l t 2 , ' s t r i n g ' ) ) ;

113 - b • s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 3 , ' s t r i n g ' ) ) ;

114 - n • s t r 2 d o ub l e ( g e t j h a n d l e s . e d i t 4 , ' s t r i n g ' ) ) ;

115 - y O = s t r 2 d o ub l e ( g e t ( h a n d l e s . e d 1 t S , ' s t r i n g ' ) ) ;

116 - xO•a;

117 - h• (b-e.) / n;

118 - far i '"' l : n

119 - kl=f ( x O , y O ) ;

120 - k2�f(x□+h/2,y0+(h/2)•kl);

121 - k3•f(xO+h/2,yO+(h/2)•k2);

122 - ki=f(x□+h,y□+h•k3);

123 - yl=yO+h•(k1+2•k2+2•k3+k4)/6;

124 - xl=xO+h;

125 - xO•x 1 ;

126 - yO=yl;

127 - end

128 - set (handles.edit6,'str1ng',yl);

CÓDIGO DEL GRÁFICO

22
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

1 1
155 f1=get(handles.edit1, string ) ;

1 1
156- f=inline(fl, x ,'y');

157 - ezmesh ( f ) ;

158 grid on

XVII. SISTEMA DE ECUACIONES DIFERENCIALES

SISTEMA ECUACIONES DIFERENCIALES

Ingresar M (x,y1 ,y2) :

lngreear t:2(x,y1 ,y2) :

Ingresar xO :

Ingresar b :

lngreear y1 :

Ingresar y2 :

1 1

Nro de

1 1

1,m,1.;1 Valor de Y3 :

1 1

Valor de y.t :
1 1

CÓDIGO DEL PROGRAMA

23
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

224 - f2•get(handles.edit2,'string');

1
225 - g• inl ine ( f 2 , ' x ' , ' y 1 , ' y2 • ) ;

226 - x 0 • s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 3 , ' s t r i n g ' ) ) :

227 - b • s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 'l , ' s t r i n g ' ) ) :

228 - y l • s t r 2 d o ub l e ( g e t ( h a n d l e s . e d i t 5 , ' s t r i n g ' ) ) :

229 - y 2 • s t r 2 do ub l e ( g et ( h a n d l e s . e ct i t 6 , 'string')):

230 - n • s t r 2 d o ub l e ( g e t ( h a n d l e s . e ct i t 9 , ' s t r i n g ' ) ) :

231

232 - h ,: ( b - x 0 ) / n

ZJJ \ h•0.S

ZJ4 \Sirve para que repita lo que esta dentro de for hasta n(iteraciones),

ZJS \n es tanbien los subintervalos.

236 - for i•l:n

237 - Kl•f(x0,yl,y2);

238 - Rl•g(x0,yl,y2);

239 - K2•f (x0+h/2, yl+h/2 "Kl, y2+h/2 "Rl) ;

240 - R2•gjx0+h/2,yl+h/2"Kl,y2+h/2•Rl);

241 - K3•f(x0+h/2,yl+h/2"K2,y2+h/2•R2);

242 - R3•g(x0+h/2,yl+h/2•K2,y2+h/2"R2);

243 - K4•f(x0+h,yl+h"K3,y2+h"R3);

244 - R 4 • g ( x 0 + h , y l + h " K 3 , VZ + h " R 3 ) ;

245 - y 3 • y l + ( h / 6 ) " ( K 1 + 2 " K2 + 2 " K 3 + K 4 )

246 - y4,:y2+ (h/6) • (Rl+2 "R2+2 "R3+R4)

247 - x l•x0+h;

248 - x0•xl;

249 - yl•y3

250 - y2,:y4

251 - end

asa

253- set(handles.edit7,'string',y3);

254 - ee t t nend r e eied rua , ' s t r i n g ' , y '! ) ;

XVIII. ECUACIONES DE ORDEN SUPERIOR


LWllod 1

ECUACl □NES DIFERENCIALES

□ROEN SUPERl □R
Ecuación Diferencial:

1
Y"(O)
B
1

u1 Y"'(O)
1 1

u2

§
- -
n

24
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

CÓDIGO DEL PROGRAMA

99 U • i n H n c ( ' u.2 ' , ' x ' , ' " 1 ' , ' u.2 ' ) ;

99 tz•inl1nc (�t (llandlc!l.cd1tl, ' !l t n n g ') , ' x ' , ' <l l ' , ' <l 2 ' 1 ;

100 !l•!ltr2n=(�t (llandlc!1.cd1t2, ' !l t r 1 n g ' ) ) ;

101 b•!ltr2dou.blc (�t (llandlc!l.cd>t3, ' !l t r 1 n g ' ) ) ;

102 ul•str2dou.blc (gct (llandlc!l.cd>t'I, ' s t n n g ' ) ) ;

103 u2•str2dou.blc (gct (lulndlc!l.cd>t5, ' s tr 1 n g ' ) ) ;

104 - n•str2dou.blc (gct (lulndlc,..cd1t6, ' s tr 1 n 11 ' ) ) ;

"'
106 h• (b-!ll /n;

107 x- ..,

"'
109 tor 1•1:n

HS

,u

HC k ll • tl ( K , <l l , u.2 ) ;

u, k12•t2 (K, <ll, u.2) ;

114 - k2 l•tl (K+h/2, <ll+(h/2) '1<11, u2-t (h/2) '1:12);

u, k22•t2 (K+h/2, <ll+(h/2) '1<11, u2-t (h/2) ' kl 2 ) ;

Hó kl l•tl (K+h/2, <ll+(h/2) '11::21, u2-t (h/2) '1:22);

u; kl 2 •t2 ( x+h/ 2, <ll+ (h/2) '11::21, u2-t (h/2) '1:22 ) ;

HS kil•tl (K+h, <ll+h'k3 I, u2-tb'k32);

HS k-12 •t2 ( x+h, <ll+h • k3 1, u2-tb '1:32) ;

HO

u, ul •ul+ ( h/ ti) • ( kll +2 •Jt2 1+2 '1<31-tk'l l) ;

u, u2 •u.2 + ( h/ ti) • ( kl2 +2 •k:22 +2 '1<32+1<'12) ;

u,

lZ4 - end

1Z5 !IH (hl>,ndi<!:!I .edit7, ' !l t r > ng ' , u l ) :

1Z6 - !IH(h&.ndlt:!1,t:dit8,'!ltr>ng',u.2):

XIX. DIFERENCIAS FINITAS

25
“UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN” FAIN-ESIC
CÁLCULO NUMÉRICO

1"7"11,,fin.!!X

DIFERENCIAS FINITAS

Pe

Oc

Re

Xn:I
=l 1 1
Ne
1 1

vo=I Yn:I
1 1

Respuesta:

111' ..
CÓDIGO DEL PROGRAMA

263 - p•inline(get(handles.editl,'string'));

264 - q-u n La.ne (get (handles. edlt2, ' s t r i n g ' ) ) ;

265 - r•inline (get (nend Ie e . edit3, " e c r ini;t' ) ) ;

266 - xO•str2double (get (handles. editS, ' s t r i n i;¡- ' ) ) ;

267 - yO•str2double (get (handles. edit6, ' s t r i n g ' ) ) ;

268 - xn•str2double (9et (handles. edit?, ' s t r i n i;i ' ) ) ;

269 - yn•str2double (get (nencuee . ecaca, ' s t r i n i;t ' ) ) ;

270 - N • i n p u t ( ' N um de Intervalos: ' ) ;

271 - h•(xn-xO)/N; n•N-1; x•xO;

272 - b•zeros(n,n+2);

273 - c=ee r ca (n, 1 ) ;

274- xx•zeros(n+l,1); d(l,l)•xO;d(n,l)•xn;

275 - F:zeros(n+l,2)

276 - !ar k•l:n

277 - x•x+h

278 - m•p ( x ) ; nn•q(x) s•r ( x ) ;

279

280 - ml•l+h*m/2;

281 - m2 • - 2 - ( h " 2 ) * n n / 2 ;

282 - m3•1-h*m/2;

283 - sol• ( h " 2 ) 11s;

284 - 1! k•• 1

285 - ee r-ec r-eu *yO;

286 - e rae ir k••n

287 - sol•!!ol-m3 *yn;

288 - end

289 - b(k,k)•ml; b(k,k+l)•m2 b(k,k+2)•m3

290 - e (k, 1) =ao i i xx (k+l, 1) •x;

291 - end

292 - B:b(:,2:N)

293 - s.,
294 - z•inv(B) *e,

295 - F(:,l)•xx(:,l);F(2:n+l,2)•c(:�1);

296 - set(handles.edit9,'string',F)

26

También podría gustarte