Академический Документы
Профессиональный Документы
Культура Документы
% de n numeros naturales
% 1+1/2^2 +1/3^2+ .....
clc;
r=0;
n=input('Digite el valor de n: ')
for i=1:n
r=r+i^-2;
end
function esentero(r)
if r==floor(r)
disp('es entero')
if mod(r,2)==0
disp('Es Par')
else
disp('Es Impar')
end
else
disp('no es entero')
end
function esprimo(r)
c=0;
if r==floor(r)
for i=1:r
if mod(r,i)==0
c=c+1;
end
end
if c==2
disp('Es Primo')
else
disp('No Es Primo')
end
else
disp('no es entero')
end
function fibonacci(r)
% Funcion para obtener los numeros de la serie Fibonacci menores a r
clc;
a=0;
b=1;
c=0;
fprintf('Serie Fibonacci: %d \t %d',a,b)
while c<=r
c=a+b;
a=b;
b=c;
if c<=r
fprintf('\t %d',c)
end
end
fprintf('\n')
function newtonr()
%Programa para hallar las raices de un polinomio por el metodo de Newton
%Raphson, Datos iniciales el polinomio, x0, tolerancia.
clc;
syms x;
f=input('Ingrese la funcion: ');
% x0=input('Ingrese el valor inicial: ');
% t=input('Ingrese la Tolerancia: ');
for c=-5:5
e=1;
i=0;
t=0.001;
f;
d=diff(f);
x0=c;
r=x0-(subs(f,x,x0))/(subs(d,x,x0));
while (abs(e)>t) && (i<10)
x0=r;
r=x0-(subs(f,x,x0))/(subs(d,x,x0));
e=x0-r;
i=i+1;
end
if i<10
double(r)
else
disp('La funcion no tiene Raices Reales, probar con un valor inicial
complejo')
end
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = boton_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)