Anda di halaman 1dari 13

DETERMINACION DE METODOS SIMBOLICOS EN MATLAB

1_ function y=funccion(x);
y=( x^3+x^2)^(1/3)+(x^2+1)^(1/2)/(x^3+x^2+2)^(1/3);

RESPUESTA

>> funccion(3)

ans =

4.2425

function y=derivadaderecha(x,h);
y=(feval('funccion',x+h)-feval('funccion',x))/h;

RESPUESTA
>> derivadaderecha(2,0.0001)

ans =

2.8965

function y=segundaderivada(x,h);
y =(feval('funccion',x+h)+feval('funccion',x-h)-2*feval('funccion',x))/h^2;

RESPUESTA
>> segundaderivada(1,0.00001)

ans =

0.7886

function y=terceraderivada(x,h);
y=(feval('funccion',x+2*h)-2*feval('funccion',x+h)+2*feval('funccion',x-h)-
feval('funccion',x-2*h))/2*h^3;
RESPUESTA
>> terceraderivada(1,0.00001)

ans =

0
METODO SIMBOLICO

Calculo de las cuatro derivadas


>> diff('2*x^3+x^2+x+1',x,0)

ans =

2*x^3 + x^2 + x + 1

>> diff('2*x^3+x^2+x+1',x,1)

ans =

6*x^2 + 2*x + 1

>> diff('2*x^3+x^2+x+1',x,2)

ans =

12*x + 2

>> diff('2*x^3+x^2+x+1',x,3)

ans =

12

CALCULO HASTA LA CUARTA DERIVADA POR DIFERENCIAS CENTRALES

function y= diferenciascentrales
f=input ('ingrese la funcion f');
xo=input('ingrese el punto donde se desee evaluar la derivada');
h=1;
f2=subs(f,xo+2*h);
f1=subs(f,xo+h);
fo=subs(f,xo);
f_1=subs(f,xo-h);
f_2=subs(f,xo-2*h);
primeraderivada=(f1-f_1)/(2*h)
segundaderivada=(f1-2*fo+f_1)/h^2
terceraderivada=(f2-2*f1+2*f_1-f_2)/(2*h^3)
cuartaderivada=(f2-4*f1+6*fo-4*f_1+f_2)/h^4
RESOLUCION DE EJERCICIO HASTA LA CUARTA DERIVADA

>> diferenciascentrales

ingrese la funcion f'3*x^3+2*x^2'

ingrese el punto donde se desee evalauar la derivada1

f_2 =

-1

primeraderivada =

16

segundaderivada =

22

terceraderivada =

17

cuartaderivada =

METODO DE BISECCION

function raiz=biseccion(def,x0,x1,tol)
f=inline(def)
if f(x0)*f(x1)<0
x=x0;
while abs(f(x))>tol
x=(x0+x1)/2;
if f(x0)*f(x)<0
x1=x;
else
x0=x;
end
end
raiz=x;
else
raiz='no hay cambio de signo';
end
SIMBOLICO

>> format long

>> biseccion('x^3-3',1.4,1.8,0.0001)

f=

Inline function:

f(x) = x^3-3

ans =

1.442236328125000

METODO DE NEWTON RAPSON


%METODO DE NEWTON
clc %permite borrar el area de trabajo
clear %permite borrar las variables almacenadas
fprintf(' METODO DE NEWTON\n\n\n');
%fprintf me permite ingresar comentarios de manera textual que pueden
%orientar al usuario en el uso del programa
format long;
%format long permite utilizar la máxima capacidad del computador
Xo=input ('ingrese el valor inicial\n');
Iter=input ('\ningrese el número de iteraciones\n');
Tol=input ('\ningrese la tolerancia que desea\n');
F=input ('\ningrese la función en comillas simples\n');
%input es un comando de solicitud de entrada de datos del usuario.
f=inline(F);
%El comando inline permite hacer la asignación posterior de variables %en una función.
Y1=f(Xo);
Derivada=diff(F)
%El comando diff permite calcular la derivada de una función.
Der=char(Derivada);
%regresa los valores a texto
D=inline(Der);
%inline, permite asignar a una función el valor de una variable.
De=D(Xo);
%Se evalúa la derivada en la X inicial, y así saber si es adecuada %para ejecutar
el resto del método, es decir si es diferente de cero.
Error=Tol+1;
Cont=0;
Z1= [Cont, Xo, Y1, De, Error];
%Z es una matriz la cual permitira observar lo datos como una tabla a %la finalizacion del
programa
%La sentencia While ejecuta todas las órdenes mientras la expresión %sea verdadera.
Z= [Cont, Xo, Y1, De, Error];
while Y1~=0 & Error>Tol & Cont<Iter & De~=0
X1=Xo-(Y1/De);
Y1=f(X1);
De=D(X1);
Error=abs((X1-Xo)/X1);
Cont=Cont+1;
Z(Cont,1)=Cont;
Z(Cont,2)=Xo;
Z(Cont,3)=Y1;
Z(Cont,4)=De;
Z(Cont,5)=Error;
%las z son las posiciones asignadas en la tabla a los resultados que %se observarán
Xo=X1;
end
if Y1==0
fprintf('\n\nSOLUCION:\n')
fprintf('%g es raíz\n\n',Xo);
else
if Error<Tol
SIMBOLICO

METODO DE LA SECANTE

function [Xa]=Secante()

syms x
y=input('Función:');
X0=input('Ingrese el valor de X0:');
X1=input('Ingrese el valor de X1:');
t=input('Ingrese la tolerancia:');
error=100;
while error>t
Xa=X1-((subs(y,X1)*(X0-X1))/(subs(y,X0)-subs(y,X1)))
error=abs((Xa-X1)/Xa);

X0=X1;
X1=Xa;
end

SIMBOLICO
MATRICES

>> A=[1 2 3 4 5 6 7 8 9 10; 0 1 2 3 4 5 6 7 8 9; 0 0 1 2 3 4 5 6 7 8; 0 0 0 1 2 3 4 5 6 7; 0 0 0 0 1 2 3 4 5 6; 0 0 0 0 0 1 2 3 4 5;


0 0 0 0 0 0 1 2 3 4; 0 0 0 0 0 0 0 1 2 3; 0 0 0 0 0 0 0 0 1 2; 0 0 0 0 0 0 0 0 0 1]

A=

1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 0 1 2 3 4 5 6 7 8

0 0 0 1 2 3 4 5 6 7

0 0 0 0 1 2 3 4 5 6

0 0 0 0 0 1 2 3 4 5

0 0 0 0 0 0 1 2 3 4

0 0 0 0 0 0 0 1 2 3

0 0 0 0 0 0 0 0 1 2

0 0 0 0 0 0 0 0 0 1

>> B=[0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 0 0 1 2; 0 0 0 0 0 0 0 1 2 3; 0 0 0 0 0 0 1 2 3 4; 0 0 0 0 0 1 2 3 4 5; 0 0 0 0 1 2 3 4 5 6;
0 0 0 1 2 3 4 5 6 7; 0 0 1 2 3 4 5 6 7 8; 0 1 2 3 4 5 6 7 8 9; 1 2 3 4 5 6 7 8 9 10]

B=

0 0 0 0 0 0 0 0 0 1

0 0 0 0 0 0 0 0 1 2

0 0 0 0 0 0 0 1 2 3

0 0 0 0 0 0 1 2 3 4

0 0 0 0 0 1 2 3 4 5

0 0 0 0 1 2 3 4 5 6

0 0 0 1 2 3 4 5 6 7
SUMA, RESTA, MULTIPLICACION DE MATRICES

>> A+B

ans =

1 2 3 4 5 6 7 8 9 11

0 1 2 3 4 5 6 7 9 11

0 0 1 2 3 4 5 7 9 11

0 0 0 1 2 3 5 7 9 11

0 0 0 0 1 3 5 7 9 11

0 0 0 0 1 3 5 7 9 11

0 0 0 1 2 3 5 7 9 11

0 0 1 2 3 4 5 7 9 11

0 1 2 3 4 5 6 7 9 11

1 2 3 4 5 6 7 8 9 11

>> A-B

ans =

1 2 3 4 5 6 7 8 9 9

0 1 2 3 4 5 6 7 7 7

0 0 1 2 3 4 5 5 5 5

0 0 0 1 2 3 3 3 3 3

0 0 0 0 1 1 1 1 1 1

0 0 0 0 -1 -1 -1 -1 -1 -1

0 0 0 -1 -2 -3 -3 -3 -3 -3

0 0 -1 -2 -3 -4 -5 -5 -5 -5

0 -1 -2 -3 -4 -5 -6 -7 -7 -7

-1 -2 -3 -4 -5 -6 -7 -8 -9 -9

>> A*B

ans =

10 29 56 90 130 175 224 276 330 385

9 26 50 80 115 154 196 240 285 330

8 23 44 70 100 133 168 204 240 276

7 20 38 60 85 112 140 168 196 224

6 17 32 50 70 91 112 133 154 175

5 14 26 40 55 70 85 100 115 130

4 11 20 30 40 50 60 70 80 90

3 8 14 20 26 32 38 44 50 56

2 5 8 11 14 17 20 23 26 29
DETERMINANTE, INVERSA, TRANSPUESTA

>> det(A+B)

ans =

>> det(A*B)

ans =

-1.0000

>> inv(A)

ans =

1 -2 1 0 0 0 0 0 0 0

0 1 -2 1 0 0 0 0 0 0

0 0 1 -2 1 0 0 0 0 0

0 0 0 1 -2 1 0 0 0 0

0 0 0 0 1 -2 1 0 0 0

0 0 0 0 0 1 -2 1 0 0

0 0 0 0 0 0 1 -2 1 0

0 0 0 0 0 0 0 1 -2 1

0 0 0 0 0 0 0 0 1 -2

0 0 0 0 0 0 0 0 0 1

>> A'

ans =

1 0 0 0 0 0 0 0 0 0

2 1 0 0 0 0 0 0 0 0

3 2 1 0 0 0 0 0 0 0

4 3 2 1 0 0 0 0 0 0

5 4 3 2 1 0 0 0 0 0

6 5 4 3 2 1 0 0 0 0

7 6 5 4 3 2 1 0 0 0

8 7 6 5 4 3 2 1 0 0

9 8 7 6 5 4 3 2 1 0

10 9 8 7 6 5 4 3 2 1
USO DEL COMANDO SOLVE

>> syms x

>> A=('3*x^2+2*x^+1')

A=

3*x^2+2*x^+1

>> solve('3*x^2+2*x^+1')

ans =

-2/3

>> pretty(ans)

/ 2\

|--|

| 3|

| |

\ 0 /
USO DEL COMANDO ROOTS

CALCULO SIMBOLICO INTEGRALES


INTEGRACION NUMERICA

METODO DEL TRAPECIO SIMPLE

function y=trapeciosimple(f,a,b,n)
f0=subs(f,a);
fn=subs(f,b);
h=(b-a)/2;
for i=1:n-1
x(i)=a+h*i;
end
integral=h*(f0+fn)

METODO DEL TRAPECIO COMPUESTO GENERALIZADO

function y=trapeciocompuesto(f,a,b,n)
f0=subs(f,a);
fn=subs(f,b);
h=(b-a)/n;
fs=0; % sumatoria
for i=1:n-1
x(i)=a+h*i;
fs=fs+subs(f,x(i));

SIMBOLICO
METODO DE SINPSON COMPUESTO (3/8)

function y=simpson(fun,a,b,n)
fa=subs(fun,a);
fb=subs(fun,b);
h=(b-a)/n;
s1=0;
s2=0;
for i=1:n-1
x(i)=a+i*h;
end
for i=1:2:n-1
s1=s1+subs(fun,x(i));
end
for i=2:2:n-2
s2=s2+subs(fun,x(i));
end
i=h*(fa+4*s1+2*s2+fb)/3

SIMBOLICO
INTEGRALES

Anda mungkin juga menyukai