MATLAB: How to use a model equation to fit the experimental values for solar panel characteristics

best fitcurve fittingplotr squared valuer^2solar panel

Dear Matlab users, I am having a problem to fit my experimental data to a given equation. I have to calculate the R^2 value for that fit.
% My initial values:
Isc = 0.45; Voc = 9.54/16; Is = 10^-8; Vr = (298*1.32*10^-23)/(1.6*10^-19); N = 16; rm = 1.33
My model Eq : Im = Isc – Is.*(exp(Vm./(rm*Vr*N)) – 1)
Experimental Values:
V = [0.05, 0.49, 0.89, 2.07, 3.71, 4.51, 5.49, 6.61, 6.9, 7.64, 7.85, … 8.35, 8.55, 8.6, 8.61, 8.63, 8.67, 8.7, 8.75, 8.77, 8.81, 8.82, … 8.83, 8.85, 8.87, 8.89, 8.9];
I = [0.42, 0.42, 0.41, 0.41, 0.4, 0.4, 0.4, 0.41, 0.41, 0.4, 0.4, 0.4, … 0.39, 0.38, 0.38, 0.37, 0.36, 0.35, 0.33, 0.31, 0.3, 0.29, 0.28, … 0.26, 0.25, 0.24, 0.22];
I want to plot V vs I graph first and then on the same graph plot the model equation. Then I want to find the R^2 value for that fitting.
Can someone help me please??
Thanks.

Best Answer

  • I’m not at all certain what you’re doing, but this works:
    % Isc = b(1); Voc = b(2); Is = b(3); Vr = b(4); N = b(5); rm = b(6)
    Im = @(b,Vm) b(1) - b(3).*(exp(Vm./(b(6).*b(4).*b(5))) - 1);
    V = [0.05, 0.49, 0.89, 2.07, 3.71, 4.51, 5.49, 6.61, 6.9, 7.64, 7.85, 8.35, 8.55, 8.6, 8.61, 8.63, 8.67, 8.7, 8.75, 8.77, 8.81, 8.82, 8.83, 8.85, 8.87, 8.89, 8.9];
    I = [0.42, 0.42, 0.41, 0.41, 0.4, 0.4, 0.4, 0.41, 0.41, 0.4, 0.4, 0.4, 0.39, 0.38, 0.38, 0.37, 0.36, 0.35, 0.33, 0.31, 0.3, 0.29, 0.28, 0.26, 0.25, 0.24, 0.22];
    B0 = [0.45; 9.54/16; 10^-8; (298*1.32*10^-23)/(1.6*10^-19); 16; 1.33];
    B = nlinfit(V, I, Im, B0);
    SStot = sum((I - mean(I)).^2); % Compute R-squared
    SSres = sum((I - Im(B,V)).^2);
    Rsq = 1 - (SSres/SStot);
    figure(1)
    plot(V, I, 'bp')
    hold on
    plot(V, Im(B,V), '-r')
    hold off
    grid