You are on page 1of 3

AJUSTE DE CURVAS

X=[0.9 1.5 3 4 6 8 9.5] subplot(2,2,4)


Y=[0.9 1.5 2.5 5.1 4.5 4.9 6.3] x1=linspace(X(1),X(7),100);
p6=polyfit(X,Y,6);
for n=1:3 ycalc66=polyval(p6,x1);
subplot(2,2,n); ycalc6=polyval(p6,X);
p=polyfit(X,Y,n); %coeficiente R
ycalc=polyval(p,X); nelem=length(Y);
yp=sum(Y)/nelem;
x1=linspace(X(1),X(7),100); N=sum((ycalc6-yp).^2);
ycalc1=polyval(p,x1); D=sum((Y-yp).^2);
%coeficiente R r=N/D;
nelem=length(Y); %--------------
yp=sum(Y)/nelem; plot(X,Y,'o',x1,ycalc66)
N=sum((ycalc-yp).^2); title(sprintf('Grado del
D=sum((Y-yp).^2); polinomio %d',6));
r=N/D; xlabel(sprintf('R= %7.7f',r));
%--------------
plot(X,Y,'o',x1,ycalc1)
title(sprintf('Grado del polinomio %d',n));
xlabel(sprintf('R= %7.7f',r));

end
GUIDE- AJUSTE DE CURVAS

function grado_Callback(hObject,
eventdata, handles)

global n;% se define la variable n


para usar en todo el código

contenido=get(handles.grado,'string');
a=get(hObject,'value');
tipo=contenido(a);
n=str2num(cell2mat(tipo));

function Graficar_Callback(hObject, eventdata, handles)

%X=[0.9 1.5 3 4 6 8 9.5]


%Y=[0.9 1.5 2.5 5.1 4.5 4.9 6.3]
global n;

%n=get(handles.grado,'value')
%Capturo los datos de la tabla
t=str2double(get(handles.tabla,'data'));
X=t(:,1);
Y=t(:,2);
% Graficando
p=polyfit(X,Y,n);
ycalc=polyval(p,X);

%gráfica con curvas


X1=linspace(X(1),X(7),100);
ycalc1=polyval(p,X1);
axes(handles.axes1)
plot(X,Y,'o',X1,ycalc1);
grid minor

%R
nelem=length(Y);
yp=sum(Y)/nelem;
N=sum((ycalc-yp).^2);
D=sum((Y-yp).^2);
r=N/D;
% Mostrar el R-r coeficientes-p
set(handles.R,'string',r)
set(handles.Tabla,'data',p');
function Calcular_Callback(hObject, eventdata, handles)
% hObject handle to Calcular (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

global n;
%n=get(handles.grado,'value');
t=str2double(get(handles.tabla,'data'));
X=t(:,1);
Y=t(:,2);
p=polyfit(X,Y,n);
x=eval(get(handles.xx,'string'));% capturando el valor de x
valor=polyval(p,x);
set(handles.valor,'string',valor)

function cerrar_Callback(hObject, eventdata, handles)


% hObject handle to cerrar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close();

You might also like