Having problems with lsqnonlin function

Hello guys, I have an equation I am trying to fit to voltage and current. The problem that I have is that the equation has the current (Jcal) in both sides of the equation and I can't simplify the equation. Is there a way to bypass this problem and have MatLab fit the equation to data? I have four unknowns and here is what the program looks like.
J=current(1,:);
V=voltage(1,:);
q=1.60e-19; % C
k=1.38e-23; % m2 Kg s-2 K-1
T=298; % Kelvin
L0=[2 0.1 0.1 0.1];
L=lsqnonlin('recfun',L0);
Jcal=L(4)/(L(4)+L(3))*(L(2)*(exp(q*(V-Jcal*L(3))/L(1)*k*T)-1)+V/L(4));
Thanks,
Francisco

댓글 수: 2

Andrew Newell
Andrew Newell 2011년 7월 17일
To fit an equation to data, you need to have some parameters that you can vary. But as far as I can tell from the above code, all the parameters are fixed - unless there is something I need to know about "recfun".
Francisco
Francisco 2011년 7월 18일
Hey Andrew,
I am varying several parameters, actually four! :) Which may too many for one single equation, but I guess it's worth trying!! ;) I am fitting the values of J and V to the equation by varying the values of L.
Francisco

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 7월 17일

0 개 추천

For whatever it is worth,
Jcal = (L(1)*(L(4)+L(3))*LambertW(q*k*T*L(3)*L(2)*L(4)*exp(T*(L(2)*L(4)*L(3)+V*L(4))*q*k/L(1)/(L(4)+L(3)))/L(1)/(L(4)+L(3))) - q*k*T*L(3)*(-V+L(2)*L(4)))/q/k/T/L(3)/(L(4)+L(3))

댓글 수: 4

Francisco
Francisco 2011년 7월 18일
Hey Walter,
I am not sure how you were able to simplify Jcal, but I will definitely look into this equation!! Maybe my math is too rusty and I forgot algebra!! :D Thanks for taking the time to write the equation in terms of Jcal only, can you illuminate me and tell me how you were able to extract Jcal from an exponent?
Francisco
Francisco
Andrei Bobrov
Andrei Bobrov 2011년 7월 18일
use Symbolic Toolbox (MuPAD)
>> solve('Jcal=L(4)/(L(4)+L(3))*(L(2)*(exp(q*(V-Jcal*L(3))/L(1)*k*T)-(1))+V/L(4))','Jcal')
ans =
(V - L(2)*L(4))/(L(3) + L(4)) + (L(1)*lambertw(0, (T*k*q*L(2)*L(3)*L(4)*exp((T*V*k*q)/L(1)))/(L(1)*exp((T*k*q*L(3)*(V - L(2)*L(4)))/(L(1)*(L(3) + L(4))))*(L(3) + L(4)))))/(T*k*q*L(3))
Walter Roberson
Walter Roberson 2011년 7월 18일
Yes, solved in the way Andrei indicates.
LembertW is a non-algebraic function suitable for solving y*exp(y)=x. It works well over a limited class of equations, but it doesn't take much of a tweak of the equation before it is unsuitable.
Francisco
Francisco 2011년 8월 5일
Awesome guys, I love MatLab now even more!! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by