Vous êtes sur la page 1sur 13

EJERCICIOS CON MATLAB

1. Representacin de un polinomio

>> p=[5 1 3 4]

PRACTICA
p=

5 1 3 4

>> r=roots(p)

r=

0.2850 + 0.9786i

0.2850 - 0.9786i

-0.7700

2.evaluacion de un polinomio

>> p=[5 1 3 4]

p=

5 1 3 4

>>xi=2.2;

>>yi=polyval(p,xi)

yi =

68.6800

3.Hallar el polinomio de interpolacin que pasa por los puntos (1.1,3.665),(2.5,4.367),


(3.6,4.341),(5.2,2.017)

>> x=[1.1,2.5,3.6,5.2]

x=

1.1000 2.5000 3.6000 5.2000

>> y=[3.665,4.367,4.341,2.017]
y=

3.6650 4.3670 4.3410 2.0170

>> a=polyfit(x,y,length(x)-1)

a=

-0.0778 0.3505 0.0345 3.3066

X=[0.0,0.25,0.5,0.75,1.0];

4.INTERPOLACIN . Hallar f( 0.27), f( 0.53), f( 0.65), f( 0. 77) mediante un polinomio de

Interpolacinde grado 4,que pasa por los puntos(0.0 , 0,916), (0.25 , 0,8109), (0.5 ,
0,6931),(0.75 , 0,5596), (1.0 , 0,4055).

>> x=[0.0,0.25,0.5,0.75,1.0]';

y=[0.916,0.8109,0.6931,0.5596,0.4055]';

xi=[0.27 0.53 0.65 0.77]';

yi=interp1(x,y,xi,'linear');

>> [xi,yi]

ans =

0.2700 0.8015

0.5300 0.6771

0.6500 0.6130

0.7700 0.5473

GRAFICOS BIDIMENSIONALES
5.graficar los puntos (3,2),(5,0),(2,3),(1,4),(4,1)

>> x=[3 5 2 1 4]; y=[2 0 3 4 1];

>>plot(x,y)
.

6.-Grafica de la funcin y=sin(x)

>> x=[-10:0.2:10]; y=sin(x);

close

plot(x,y)

grid

xlabel('x');ylabel('y')
7.Graficadec dos funciones,y=sin(x);z=cos(x)

>> x=0:pi/20:4*pi;

>>y=sin(x); z=cos(x);

>>plot(x,y,'.',x,z,'-')

>>grid
GRAFICA DE ECUACION NO LINEAL
8.Graficar f ( x )=cos (x)cosh ( x)+1

>> x=-5:0.1:5;

>> y=cos(x).*cosh(x)+1;

>>plot(x,y);

>>grid

>>xlabel('x');ylabel('y=cos(x)*cosh(x)+1')
9.GRAFICAS , INTERPOLACION CON POLINOMIOS DE GRADO 5 Y 10

En el intervalo [0 10] con un paso de 0.1

>> x=0:10;

>>xx=0:0.1:10;

>> y=sin(x);

>> p5=polyfit(x,y,5);

>> p10=polyfit(x,y,10);

>> plot(x,y,'o',xx,polival(p5,xx),'-',x,y,'y',xx,polyval(p10,xx),'.')

10.-GRAFICAS SPLINES CON 3 Y 5 PUNTOS

%spline cubico con 3 puntos(2,1),(3,0),(5,4)

>> x=[2 3 5]; y=[1 0 4];

>>xx=2:0.1:5;

>>plot(xx,csapi(x,y,xx),'k-',x,y,'ro'),grid
>>title('spline con 3 puntos')

11.%spline cubico con 5 puntos (1,1),(1.5,-1),(2,1),(4.1,-1),(5,1)

>> x=[1 1.5 2 4.1 5]; y=[1 -1 1 -1 1];

>>xx=[1:0.1:5;]

xx =

Columns 1 through 7

1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000

Columns 8 through 14

1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000

Columns 15 through 21

2.4000 2.5000 2.6000 2.7000 2.8000 2.9000 3.0000

Columns 22 through 28
3.1000 3.2000 3.3000 3.4000 3.5000 3.6000 3.7000

Columns 29 through 35

3.8000 3.9000 4.0000 4.1000 4.2000 4.3000 4.4000

Columns 36 through 41

4.5000 4.6000 4.7000 4.8000 4.9000 5.0000

>>plot(xx,csapi(x,y,xx),'k-',x,y,'ro')

>>grid

>>title('spline cubico con 5 puntos')

12.APLICACIN DEL SPLINE,GRAFICA DE UNA PIEZA

>>x1=[-2 -1.5 -1 -0.5 0 0.5 1 1.5 2];

>> y1=[0 0.4 0.8 1 1.4 1.8 2 2.5 5];

>>x2=[2 2.2 2.5 2.8 3];

>> y2=[5 4.5 4 3.5 3];


>>x3=[-2 -1 -0.5 0 1 1.5 2 2.5 3];

>> y3=[0 -0.2 -0.5 -1 0 1 1.5 1.6 3];

>>plot(x1,y1,'x',x2,y2,'+',x3,y3,'.')

>> xx1=-2:0.1:2;

>> xx2=2:0.1:3;

>> xx3=-2:0.1:3;

>>
plot(xx1,csapi(x1,y1,xx1),'k-',x1,y1,'ro'xx2,csapi(x2,y2,xx2),'k-',x2,y2,'ro',xx3,csapi(x3,y3,xx3),'k-',x3,
y3,'ro')

13.-ECUACION NO LINEAL

Primera forma: con la instruccin fzero.


>> x=-5:0.1:10;

>> f=0.5*exp(x/3)-sin(x);

>> close

>>plot(x,f)

>>grid

>> x=-5:0.1:10;

>> f=inline('0.5*exp(x73)-sin(x)')

f=

Inlinefunction:

f(x,x73) = 0.5*exp(x73)-sin(x)

>>fzero(f,0.5)
14.-Segunda forma con el mtodo de newton:

>> x=[0:0.2:2];

>> y=[-0.3:0.2:0.3];

>> y=0.5*exp(x/3)-sin(x);

>>close

>>plot(x,y)

>>grid

>>sym x;

15.-SISTEMA DE ECUACIONES NO LINEALES

Ejemplo, primera forma con fsolve

( x2 )2 + ( x2 y3+2 x )25=0

2 ( x 3 )2+ ( y /3 )24=0
Grfica del sistema:

>> a=-4:0.1:8;b=-8:0.1:8;[x,y]=meshgrid(a,b);

>> f1=(x-2).^2+(y-3+2*x).^2-5;f2=2*(x-3).^2+(y/3).^2-4;

>>close

>>contour(x,y,f1,[0,0],'k');hold on;grid on;

>>contour(x,y,f2,[0,0],'k');

>> f=inline('[x(1)-2).^2+(x(2)-3+2*x(1)).^2-5;2*(x(1)-3).^2+(x(2)/3).^2-4]')

f=

Inlinefunction:

f(x) = [x(1)-2).^2+(x(2)-3+2*x(1)).^2-5;2*(x(1)-3).^2+(x(2)/3).^2-4]

x=fsolve(f,[1.5,-3],optimset('fsolve'))

>> f=[x(2)-x(1).^2;x(1).^2+x(2).^2-4]

f=

-20
28

>> %x(1)=x; x(2)=y

>> X0=[1.5,-3];

>> X=fsolve('experimentro1',X0)

Vous aimerez peut-être aussi