Академический Документы
Профессиональный Документы
Культура Документы
Curvas paramtricas
>>t=linspace(-5,5,1000);
>>plot((t.*(t.^2-1))./(t.^2+1),(2*(t.^2-1))./(t.^2+1))
Curvas en el espacio:
>>t=linspace(0,8*pi,2000);
>>plot3(sin(t),cos(t),t),grid on
Curvas de la forma
y=f ( x , y )
>>[x,y]=meshgrid(-2:.5:2);
>>z=exp(-x.^2-y.^2);
>>plot3(x,y,z)
>>mesh(x,y,z)
>>surf(x,y,z)
>>surf(x,y,z)
Ejercicio 1 Biseccin
BOLZANO:
% bolzano2.m
function[raiz,z,it]=bolzano2(f,a,b,TOL)
UNIVERSIDAD NACIONAL MAYOR DE SAN MARCOS Pgina 5
f=inline('exp(-x)-x');
z=[];
for it=1:1000
x=(a+b)/2;
err=(b-a)/2;
z=[z; a x b err];
if feval(f,a)*feval(f,x)<0
b=x;
else
a=x;
end
if err<TOL
break
end
end
raiz=x;
Ejercicio 2: localizacin
a) Races de la funcin
x /3
f ( x )=
e
sen (x)
2
en el
% fun1.m
function [f]=fun1(x)
f=1/2*exp(x/3)-sin(x);
% Localiza.m
clc, clear all, format short
x=-10:10;
y=fun1(x);
plot(x,y),grid
disp('x vs y')
disp([x' y'])
% Intervalos que contienen raices
acu=[];
for i=1:length(x)-1
if y(i)*y(i+1)<0, acu=[acu; x(i) x(i+1)];
end
end
disp('Intervalos que contienen raices...');
disp(acu)
iter=iter+1;
end
F ' ( x )=
2 x 1sen ( x 2) =0
fr x=(x 1 , x 2 )
4 x 2exp (x 1) =0
2cos ( x 2 )
exp ( x 1 ) 4
En matlab
function [y,J]=F(x)
y=[2*x(1)-sin(x(2)); 4*x(2)-exp(-x(1))];
J=[2, -cos(x(2)); exp(-x(1)), 4];
Para hacer un paso de newton usar la funcin:
function y = newtonstep(x)
[y,J] = F(x);
UNIVERSIDAD NACIONAL MAYOR DE SAN MARCOS Pgina 15
dx = - J \ y;
y = dx + x;
Para aplicar Newton al problema
clear all
x0=[0 0]';
maxit=50;
tol=0.5e-3;
H=[0 x0' 1];
x=x0;
for i=1:maxit
y = newtonstep(x);
e=norm(y-x,inf);
H=[H; i y' e];
if e<tol
break
end
x=y;
end
disp(' i
x1
x2
error')
fprintf('%4.0f %12.8f %16.8f %20.8e \n',H')