Sei sulla pagina 1di 11

1.

format short
disp('Representacin de un polinomio')
disp('5x^3+x^2+3X+4')
p=[5 1 3 4]
disp('Hallamos sus raices:')
r=roots(p)

Representacion de un polinomio
5x^3+x^2+3X+4

p =

5 1 3 4

Hallamos sus raices:

r =

0.2850 + 0.9786i
0.2850 - 0.9786i
-0.7700 + 0.0000i

2. Evaluacion de un polinomio
5x^3+x^2+3X+4
y(2,2)=?

p =

5 1 3 4

yi =

68.6800

3. Hallar el polinomio de interpolacion 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]
Y=[3.665;4.367;4.341;2.017]
a=polyfit(x, y, length(x)-1)

x =

1.1000 2.5000 3.6000 5.2000


y =

3.6650 4.3670 4.3410 2.0170

a =

-0.0778 0.3505 0.0345 3.3066

4. Hallar f(0.27), f(0.53, f(0.65), f(0.77) mediante un


polinomio de interpolacion de 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]'; %hallamos las imagenes de xi
yi=interpl(x, y, xi, 'linear'); %usar solo linear o cubic
[xi, yi]
%aparece el resultado
y =

0.9160
0.8109
0.6931
0.5596
0.4055

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. Grafica de 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

8. Graficar: f(x)=cso(x)cosh(x)+1
elf; clear % o clg; clear
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. 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,polyval(p5,xx),'-',x,y,'y',xx,polyval(p10,xx),'.')
10. %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;
plot(xx,csapi(x,y,xx),'k-',x,y,'ro')
grid
title('spline con 5 puntos')

12. 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,'.') %dibujo del contorno
xx1=-2:0.1:2; %limites
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')
% es una sola linea
13. disp('primera forma: con la instruccion fzero')
disp('0.5*exp(x/3)-sin(x)=0')
disp('Grafica de la ecuacion')
x=-5:0.1:10;
f=0.5*exp(x/3)-sin(x)

f =

Columns 1 through 12

-0.8645 -0.8848 -0.8952 -0.8956 -0.8858 -0.8660


-0.8363 -0.7969 -0.7483 -0.6908 -0.6250 -0.5515

Columns 13 through 24

-0.4710 -0.3842 -0.2919 -0.1951 -0.0946 0.0087


0.1137 0.2195 0.3251 0.4294 0.5316 0.6307

Columns 25 through 36

0.7257 0.8158 0.9001 0.9780 1.0486 1.1115


1.1660 1.2117 1.2483 1.2754 1.2929 1.3008

Columns 37 through 48
1.2990 1.2877 1.2672 1.2377 1.1997 1.1537
1.1003 1.0402 0.9740 0.9027 0.8270 0.7479

Columns 49 through 60

0.6664 0.5834 0.5000 0.4171 0.3358 0.2571


0.1819 0.1113 0.0461 -0.0128 -0.0646 -0.1084

Columns 61 through 72

-0.1437 -0.1697 -0.1861 -0.1924 -0.1881 -0.1731


-0.1473 -0.1105 -0.0628 -0.0044 0.0646 0.1437

Columns 73 through 84

0.2325 0.3306 0.4373 0.5520 0.6740 0.8024


0.9365 1.0753 1.2180 1.3636 1.5112 1.6598

Columns 85 through 96

1.8085 1.9564 2.1026 2.2462 2.3864 2.5224


2.6536 2.7794 2.8992 3.0125 3.1190 3.2184

Columns 97 through 108

3.3105 3.3952 3.4727 3.5429 3.6062 3.6628


3.7132 3.7579 3.7976 3.8329 3.8646 3.8936

Columns 109 through 120

3.9209 3.9473 3.9739 4.0019 4.0323 4.0663


4.1049 4.1494 4.2010 4.2606 4.3295 4.4087

Columns 121 through 132

4.4991 4.6019 4.7179 4.8480 4.9928 5.1532


5.3298 5.5230 5.7333 5.9611 6.2066 6.4700

Columns 133 through 144

6.7513 7.0506 7.3677 7.7025 8.0548 8.4241


8.8102 9.2125 9.6306 10.0641 10.5122 10.9745

Columns 145 through 151

11.4504 11.9393 12.4406 12.9538 13.4784 14.0139


14.5598

close

plot(x,f)
grid

%para hallar la solucion

x=-5:0.1:10;

f=inline('0.5*exp(x/3)-sin(x)')

fzero(f,0.5)

f =

Inline function:

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

ans =

0.6772

14. segunda forma con el metodo 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

15. primera forma con fsolve


a=-4:0.1:8;b=-8:0.1:8;[x,y]=meshgrid(a,b);
fl=(x-2).^2+(y-3+2*x).^2-5;f2=2*(x-3).^2+(y-3).^2-4;
close
contour(x,y,fl,[0,0],'k');hold on; grid on;
contour(x,y,f2,[0,0],'k');

Potrebbero piacerti anche