fminsearch for non linear regression Matlab?

769 Views Asked by At

Can anyone explain to me how I can apply fminsearch to this equation to find the value of K (Diode Equality Factor) using the Matlab command window.

I = 10^-9(exp(38.68V/k)-1)

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]:

I used fminsearch and an 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)    

Please explain what the problem in this code is?

1

There are 1 best solutions below

1
On BEST ANSWER

It looks like you are carrying on from this post: Fminsearch Matlab (Non Linear Regression ). The linked post is trying to find the right coefficient k in your equation that minimizes the sum of squared errors between the input, which is predicted current from the current-voltage relation of a diode and the output, which is the measured current from a diode. This current post is simply trying to get that off the ground.

In any case, this is a very simple error. You're missing an element in your current array I. It's missing one 0. You can verify this by using numel on both V and I. Basically, V and I don't match in size. numel(V) == 11 and numel(I) == 10.

The definition you have at the top of your question compared to how you defined your error, it's missing one final zero:

I = [0, 0, 0, 0, 0, 0, 0, 0.07, 0.92, 12.02, 158.29];
%//                    ^

When I run the code with this new I, I get:

>> kmodel

kmodel =

    1.4999