0

I have to solve some parabolic PDE system with pdepe in Matlab. is't possible and secure to call Fzero function inside boundary conditions function in Pdepe solver like this?

function [pl,ql,pr,qr] = pdex5bc(~,ul,~,ur,~)
kappa = nref*Dref*q/L;
jcell0 = 0;
k0 = 0.1; 
options = optimset('Display','iter'); % show iterations
jcell = fzero(@curOc,k0,options); % Call solver

pl = [jcell0 ; -1/(2*epsilonp)*jcell0/kappa ; 3/(2*epsilonp)*jcell0/kappa ;...
      jcell  ; -1/(2*epsilonp)*jcell/kappa ;  3/(2*epsilonp)*jcell/kappa];
ql = [kappa ; 1 ; 1 ; kappa ; 1 ; 1];
pr = [0 ; -1/(2*epsilonp)*jcell0/kappa ; 3/(2*epsilonp)*jcell0/kappa ;...
      0 ; -1/(2*epsilonp)*jcell/kappa ;  3/(2*epsilonp)*jcell/kappa];
qr = [1 ; 1 ; 1 ; 1 ; 1 ; 1];

    function F = curOc(z)
    deltaVint = (Rtco+Rext)*(Rp/(Rext+Rtco+Rp))*A*z*J0;
    Eta =  Pot+Vt/2*log(ur(2)/ur(3)^3)+Vt*log(ul(4)/Ncb)- deltaVint ;   
    F = z - (ur(5)/ur(2)*exp(beta*Eta/Vt)- ur(6)/ur(3)*exp(-(1-beta)*Eta/Vt));
    end 
end

Let me expose my problem : When I execute this code, following error occurs:

*Error using fzero (line 289) FZERO cannot continue because user supplied function_handle ==> pdeDSSC_new8bis/pdex5bc/curOc failed with the error below. User function 'pdeDSSC_new8bis/pdex5bc/curOc' returned a complex value when evaluated at 20;* FZERO cannot continue.

At some time integration of pdepe,fsolve returns a complex root. This happens when ul and ur become negatives. Does someone can explain to me the problem?

2
  • What is your error? You've provided code, but it's not runnable on it's own. Is the function definition curOc nested within the function definition for pdex5bc? Are you sure you mean "nested" and not sub-function? If it really is a nested function, then you need to take special care of the variable that have scope in both the outer function and the inner one.
    – horchler
    Oct 24, 2013 at 13:36
  • thank you Horchler for the remark. I didn't know the difference but my part of code looks like above after modification. Oct 24, 2013 at 14:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.