Ajuste RLC subamortiguado

Contents

Borro todas variables y graficos previos

clear all
close all

pause on

Genero algunos datos de prueba y los grafico

global to Io t I     % Quiero poder usar estas variables en todo el programa,
                     % incluyendo subrutinas/funciones/modulos etc.

to = linspace(0 , 6 , 400)';     % [s]

Vo  = 1000;         % [V]
Lo   = 10;          % [H]
Co   = 1e-6;        % [F]
Ro   = 10;          % [Ohm]

% Defino 3 variables auxiliares y el periodo To
Bo  = Ro/2/Lo ;
Do  = sqrt(1/(Lo*Co) - Bo^2) ;
Ao  = Vo/Do/Lo ;

To  = 1.5;

% Defino la corriente Io (ideal -- sin incerteza)
Io   = Ao * exp(-Bo * to) .* sin( (2*pi/To) .* to) ;

% Ahora defino la corriente I (real -- con incerteza agregada)
I   = Io .* (1 + 0.005 .* random('norm',0,1,size(Io)) );

% Le agrego incerteza tambien a la lista de tiempos
t   = to .* (1 + 0.005 .* random('norm',0,1,size(to)) );

% Grafico los "datos" ideales y con ruido
figure(1)
plot(to,Io,'.--',t,I,'+','LineWidth',1.5)
grid on
xlabel('{\it{t}} (s)')
ylabel('{\it{I}} (A)')
title('Datos RLC subamortiguado')
legend('Curva teorica','Datos con ruido','Location','northeast')

% disp('Colocar el cursor en la ventana de comandos y apretar cuaquier tecla')
% pause

Ajuste No Lineal por Cuadrados Minimos donde: "y = f(x)"

x = t;
y = I;

fit_Type    = fittype( 'RLCsub( x, A, B, T )' );

fit_Object_1 = fit( x, y, fit_Type, ...
    'StartPoint', [10*Ao, 10*Bo, 1.2*To ], ...
    'MaxFunEvals',3000, 'MaxIter',2500, 'TolFun',1e-14, 'TolX',1e-14)

% disp('Colocar el cursor en la ventana de comandos y apretar cuaquier tecla')
% pause
fit_Object_1 = 

     General model:
     fit_Object_1(x) = RLCsub( x, A, B, T )
     Coefficients (with 95% confidence bounds):
       A =      0.3172  (0.3159, 0.3185)
       B =      0.5027  (0.4997, 0.5058)
       T =       1.499  (1.499, 1.5)

Grafico el intervalo de confianza

Interv_Conf = predint(fit_Object_1,x,0.99,'observation','on');

figure(3)
plot(x,y,'b+--','LineWidth',1.5)
hold on
plot(fit_Object_1,'k-')
hold on
plot(x,Interv_Conf,'m--','LineWidth',1.5), xlim([0 6])
title('Ajuste RLC subam. con Intervalo de Conf. del 99%')
grid on
hold off


% disp('Colocar el cursor en la ventana de comandos y apretar cuaquier tecla')
% pause

Salida mas avanzada

[fit_Object_2,gof,output] = fit( x, y, fit_Type, ...
    'StartPoint', [20*Ao, 5*Bo, 0.8*1.5], ...
    'MaxFunEvals',3000, 'MaxIter',2500, 'TolFun',1e-14, 'TolX',1e-14)

pause off
fit_Object_2 = 

     General model:
     fit_Object_2(x) = RLCsub( x, A, B, T )
     Coefficients (with 95% confidence bounds):
       A =      0.3172  (0.3159, 0.3185)
       B =      0.5027  (0.4997, 0.5058)
       T =       1.499  (1.499, 1.5)

gof = 

           sse: 0.0027
       rsquare: 0.9992
           dfe: 397
    adjrsquare: 0.9992
          rmse: 0.0026


output = 

           numobs: 400
         numparam: 3
        residuals: [400x1 double]
         Jacobian: [400x3 double]
         exitflag: 3
    firstorderopt: 4.9600e-10
       iterations: 9
        funcCount: 40
     cgiterations: 0
        algorithm: 'trust-region-reflective'
          message: 'Success, but fitting stopped because change in residua...'