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
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
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
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
>> biseccion('x^3-3',1.4,1.8,0.0001)
f=
Inline function:
f(x) = x^3-3
ans =
1.442236328125000
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
>> 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 =
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
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)
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