data = [    0.550   24  1;

            0.900   37  1;

            1.250   49  1;

            1.450   67  1;

            1.8     77  1;

            2.15    90  1;

            2.3    104  1;

            2.5    113  2;

            2.7    120  2;

            3      142  2;

            3.2    155  2;

            3.5    180  2;

            3.7    200  2;

            4.2    220  2];

      

N = length(data(:,1));

errorbar(data(:,1),data(:,2),data(:,3),'o','markersize',4);

xlim([0 4.5]);

fs = 14;

xlabel('Input IR power (W)','fontsize',fs);

ylabel('Measured green power (mW)','fontsize',fs);

title('Efficiency of frequency conversion','fontsize',fs);

grid on;



function_linear = @(x,a) a(1)*x + a(2);

dYda = {@(x,a) 1}; sgn = 0;

m = (data(N,2)-data(1,2))/(data(N,1)-data(1,1));

b = data(1,2) - m*data(1,1);

a0 = [m b];

[a,aerr,chisq,yfit,corr] = levmar(data(:,1),data(:,2),data(:,3),...

    function_linear,a0,dYda,sgn);

x = linspace(0,4.5);

y = function_linear(x,a);

hold on;

plot(x,y,'r','linewidth',2);

ylim([0 250]);