I am using newton -raphson method .. the code for newton method is ..
function [x,f,ea,iter] = newtmult (func,x0,es,maxit,varargin)if nargin<2,error('atleast 2 input arguments required'),endif nargin<3||isempty(es),es=0.0001;endif nargin<4||isempty(maxit),maxit=50;enditer = 0;x = x0;while (1) [J,f] = func(x,varargin{:}); [L,U] = lu(J); dx = U\(L\f); x = x - dx; iter = iter+1; ea = 100*max(abs(dx./x)); if iter>=maxit||ea<=es, break, end end
Using this function i am supposed to calculate the values of some variables of other code .. which is as follows :
% open circuit voltage irradiance and temperature dependence
% Voc1 = is the irradiance dependent Voc
% Voc2 = is the temperature dependent Voc
% Voc1 has to be calculated using Newton -Raphson method.
function [J,f] = Voccalculation4(x,varargin)%v = [ Voc1 Voc2]
Rsh = 417.5; % panel parallel (shunt) resistance.
Ns = 72 ; % no of cells connected in series.
Iph = 5.20;I0 = 4.54;G = 1000 ; % G= irradiance (different values of irradiance ) in W/m^2.
Iph1 = Iph*G; % Iph = photo-generated current in STC , obtained from previous calculation.
%I01 = I0*G ; % I0 = dark saturation current in STC,obtained from previous calculation.
Tstc = 298 ; % Tstc (K) is temperature in kelvin at STC .
K = 1.381e-23; %Boltzmann constant = 1.3806488 × 10-23 m2 kg s-2 K-1 .
q = 1.60e-19; % electron charge in coulombs.
A=1.2;Vt = (A*K*Tstc)/q ; % threshold voltage of cell-diode.
Voc = 42;T = 320 ; % operating range given in datasheet !
Kv = -0.38;format short% G is irradiance here
syms Voc1 Voc2f1= Voc1 - (log((Iph1*Rsh - Voc1)/(I0*Rsh)))*Ns*Vt;f2= Voc2 - Voc + Kv(T-Tstc); % sign before Kv is positive in standard equation.
J11 = diff(f1,'Voc1');J12 = diff(f1,'Voc2');J21 = diff(f2,'Voc1');J22 = diff(f2,'Voc2');f = zeros(2,1);f(1)= subs (f1,{Voc1,Voc2},{x(1),x(2)});f(2)= subs (f2,{Voc1,Voc2},{x(1),x(2)});J = zeros(2,2);J(1,1) = subs (J11,{Voc1,Voc2},{x(1),x(2)});J(1,2) = subs (J12,{Voc1,Voc2},{x(1),x(2)});J(2,1) = subs (J21,{Voc1,Voc2},{x(1),x(2)});J(2,2) = subs (J22,{Voc1,Voc2},{x(1),x(2)});J
I have been stuck on this code for weeks now … after trying recommendations to other users .. I am finally posting it here .. any help will be greatly appreciated !!! Thanks in advance .
Best Answer