Documentos de Académico
Documentos de Profesional
Documentos de Cultura
fun =
@(x) 1 / (1 + x ^ 2)
[2]: y=fun(3)
y = 0.1000
El comando fplot ( fun , lims ) grafica la función ‘fun’ en el intervalo (lims(1), lims(2))
[8]: fplot(fun,[-5,5]);
1
De forma alternativa el comando plot
[13]: x=linspace(-5,5,500);
fun=@(x) 1./(1+x.^2);
y=fun(x);
plot(x,y,'Linewidth',3); grid on
2
1.2 Polinomios
Para definir un polinomio ingresamos un vector con los coeficientes, por ejemplo p(x) = x7 +3x2 −1
se define de la forma
[14]: p=[1 0 0 0 0 3 0 -1];
[15]: y=polyval(p,1.23)
y = 7.7980
También lo podemos evaluar en un vector
[16]: x=-1:0.25:1
x =
Columns 1 through 8:
3
Column 9:
1.0000
[17]: y=polyval(p,x)
y =
Columns 1 through 8:
Column 9:
3.0000
ans =
0.9698 + 0.7716i
0.9698 - 0.7716i
-0.3739 + 1.2305i
-0.3739 - 1.2305i
0.5716 + 0i
-1.1793 + 0i
-0.5840 + 0i
[30]: a=5;b=4;c=3;
[31]: if a ~= 0
sq = sqrt(b*b - 4*a*c);
x1(1) = 0.5*(-b + sq)/a;
x1(2) = 0.5*(-b - sq)/a;
elseif b ~= 0
x1(1) = -c/b;
4
elseif c ~= 0
disp(' Impossible equation');
else
disp(' The given equation is an identity');
end
[33]: x1(1),x(2)
1.4 Ejercicios
1. Dado que π es la suma de
∞
∑ ( )
−n 4 2 1 1
π= 16 − − −
8n + 1 8n + 4 8n + 5 8n + 6
n=0
suma_pi =
@(n) 16 .^ (-n) .* (4 ./ (8 * n + 1) - 2 ./ (8 * n + 4) - 1 ./ (8 * n + 5) - 1
./ (8 * n + 6))
sum(suma_pi(x))
ans = 3.141592653589793
[52]: pi
ans = 3.141592653589793
[ ]: