lsqnonlin question curve fitting

5 vues (au cours des 30 derniers jours)
Theofanis
Theofanis le 23 Jan 2015
Commenté : Theofanis le 27 Jan 2015
Hello. I am trying to use lsqcurve fit and lsqnonlin commands in order to approximate a curve that derives from the set (Vi,Pi) of data, which represent the Voltage and Power measured from a photovoltaic panel
The equation that i need to use is :
P = Vi*Iph - Vi*Is * e^((Vi+Ii*Rs)/17.796) - (Vi+Ii*Rs)/Rsh.
The parameters that i need to calculate are : Iph, Is, Rsh . Rs is a known number. My problem is that i need to do it in the following way. I have a matrix V = Vi that contains all measured voltage values and P that contains all the measured power values . I also have all measured current values , which means i know all pairs of (Vi,Ii). I want to create a function that takes as inputs some elements of the V matrix ( a number of voltage measurements) but i want Ii to change every time, that means that for every given Vi i use i want to enter the Ii that makes up the pair (Vi,Ii). What i mean is that i do not want to use the Ii as measurements to help me approximate the actual curve, but i want to use them as parameters that change each time i call the function. I have searched on the net for possible solutions, but since i am new to Matlab i have had a hard time implementing it. Any help appreciated :)

Réponses (2)

Torsten
Torsten le 23 Jan 2015
Although I read your question several times, I still don't understand what you are asking for.
Could you provide a small example for explanation ?
Best wishes
Torsten.

Star Strider
Star Strider le 23 Jan 2015
I would use lsqcurvefit and then loop through the corresponding ‘Vi’, ‘Ii’ and ‘P’ values. You will get different parameter estimates with each iteration.
The function to fit:
% Original Equation: P = Vi*Iph - Vi*Is * e^((Vi+Ii*Rs)/17.796) - (Vi+Ii*Rs)/Rsh.
% Parameters: Iph = b(1), Is = b(2), Rsh = b(3)
% Independent Variables: IV = [Ii Vi]; Both Column Vectors
Pfit = @(b,IV) IV(:,2).*b(1) - IV(:,2).*b(2) .* exp((IV(:,2)+IV(:,1)*Rs)/17.796) - (IV(:,2)+IV(:,1)*Rs)./b(3);
  3 commentaires
Star Strider
Star Strider le 25 Jan 2015
Modifié(e) : Star Strider le 25 Jan 2015
My pleasure.
Your ‘myfun’ function ‘F’ assignment needs to be fully vectorised:
F = b(1)-b(2).*exp((IV(:,2)+IV(:,1).*Rs0)./a0)+(IV(:,2)+IV(:,1).*Rs0)./b(3);
since that could be the problem.
Guessing here, but also be certain that ‘Vpv’ is composed of two column vectors (that is, it is an (Nx2) matrix) and that ‘Ipv’ is an (Nx1) column vector, and that ‘myfun’ returns a (Nx1) column vector as well. That should eliminate that error. (To be certain ‘myfun’ is working correctly so it will work with lsqcurvefit, you might want to run ‘myfun’ with your initial parameter estimates and your ‘IV’ matrix once to be certain it does, before you use it in lsqcurvefit.)
Theofanis
Theofanis le 27 Jan 2015
Hello again!
Well that is what makes me wonder why it does not work . I run the function my fun, with the matrix IV as input (size Nx2) exactly as u proposed, and the output is a Nx1 vector. When i attempt to enter xdata, ydata (Vpv and Ipv matrices respectively which are both size(1xN) i get the error i mentioned.
I suspected that they should both be transposed in order to be column matrices so i entered Vpv' and Ipv' respectively and what made me wonder is the error that occured :
>> [b,resnom] = lsqcurvefit(@myfun,b0,Vpv',Ipv')
Attempted to access IV(:,2); index out of bounds
because size(IV)=[100001,1].
Error in myfun (line 11)
F =
b(1)-b(2).*exp((IV(:,2)+IV(:,1)*Rs0)./a0)+(IV(:,2)+IV(:,1)*Rs0)./b(3)
In my workspace when i type size(IV) i get the following :
>> size(IV)
ans =
100001 2
which means it is a 2 column matrix with 100001 rows, whereas in the error above it mentions that index is out of bounds because size(IV) = [100001,1].
Again, thanks for your help

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by