2

Can anyone explain to me how I can apply non linear regression to this equation t find out K using the matlab command window.

I = 10^-9(exp(38.68V/k)-1). Screenshot of Equation

I have data values as follows:

Voltage := [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]:
Current:= [0, 0, 0, 0, 0, 0, 0, 0.07, 0.92, 12.02, 158.29]:

Screenshot of Equation

[NEW]: Now I used FminSearch as an alternative another and another error message appeared.

Matrix dimensions must agree.

Error in @(k)sum((I(:)-Imodel(V(:),k)).^2)

Error in fminsearch (line 189)
fv(:,1) = funfcn(x,varargin{:});

I used this fminsearch code:

>> V = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0];
>> I = [0, 0, 0, 0, 0, 0, 0.07 ,0.92 ,12.02 ,158.29];
>> Imodel = @(V,k) 1E-9*(exp(38.68*V/k)-1);
>> k0 = 1;
>> kmodel = fminsearch(@(k) sum((I(:)-Imodel(V(:),k)).^2), k0)    
>> kmodel = fminsearch(@(k) sum((I(:)-Imodel(V(:),k)).^2), k0);
Saavin
  • 59
  • 8
  • Can you maybe post an image a a LaTeX formatted version of that formula? Are you saying there are nested powers? Either way, have you considered doing a log-linear regression (i.e. takes logs of both sides and then do a linear regression)? – Dan Feb 12 '16 at 11:58
  • Related: http://stackoverflow.com/questions/29634183/exponential-curve-fitting-without-the-curve-fitting-toolbox – jub0bs Feb 12 '16 at 13:01
  • @Dan, I have attached screenshot of the actual equation. – Saavin Feb 13 '16 at 16:24
  • @Dan: I am considering now doing a log-linear regression will 0A Current measurements add error to the linear regression? Will it improve the accuracy if I ignored those values:? – Saavin Feb 13 '16 at 16:27

1 Answers1

5

You want to find the parameter k that will minimize the sum of squared error of your exponential model (BTW, is that a current/voltage characteristic?) given the current data I and voltage data V as vectors:

Imodel = @(V,k) 1E-9*(exp(38.68*V/k)-1);
k0     = 1;
kmodel = fminsearch(@(k) sum((I(:)-Imodel(V(:),k)).^2), k0);

plot(V(:), I(:), 'ok', V(:), Imodel(V(:),kmodel), '-r');

The anonymous function calculates the sum of squared error. The search for the parameter k that will minimize the model error starts with the value 1; please change it to a more appropriate value (if you have a good guess for it).

  • 1
    I have these values, i need to find k;Voltage := [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]: Current := [0, 0, 0, 0, 0, 0, 0, 0.07, 0.92, 12.02, 158.29]: – Saavin Feb 12 '16 at 12:42
  • 6
    @Saavin Sorry, but I gave the solution already. Have you tried it? Do you need more assistance on how to apply it to your case? I looked at your profile, and I read that you are proficient in MATLAB, so I assumed you can adapt the solution to your needs. –  Feb 12 '16 at 12:53
  • @Saavin I changed the code so is more readable, plus I added a plot of data vs. model. –  Feb 12 '16 at 13:01
  • I have tried this and still an error appeared, >> f = (voltage, k) 1E-9*(exp((36.68.*voltage)/k)-1); >> nlinfit(voltage, current, f, [1 0.15829]) – Saavin Feb 12 '16 at 13:27
  • Yes this is I/V characteristic – Saavin Feb 12 '16 at 13:31
  • 4
    @Saavin I used `fminsearch` (which is a generic MATLAB function) not `nlinfit` (which comes with the statistical toolbox). What I was asking is: did you try the code that I posted? –  Feb 12 '16 at 13:36
  • Good evening sir, your solution worked and gave me a suitable answer thank you very much for your help. I now have no more errors. – Saavin Feb 13 '16 at 22:41