How fix this error: "Error CASSENS2 returns a vector of length 3, but the length of initial conditions vector is 4."."
2 views (last 30 days)
Show older comments
function xBL = calculaxBL(T)
global P A B C Psat a1 r qsi rohfo ropoliol phi1
P = 0.921;
A = 6.820820;
B= 1550.590847;
C = 17.08326013;
Psat = 10^(A-B/(T+C))/101.235;
a1 = P/Psat;
r = 3.0975;
qsi= 1.588;
rohfo=1380;
ropoliol=1100;
[X,FVAL,EXITFLAG] = fzero(@(x) log(1-x)+x*(1-1/r)+qsi*x^2-log(a1), [0.4 0.999]); % Flory-Huggins resolution to obtain phi2
if (EXITFLAG==1)
phi2 = X;
else
print "erro na fzero EXITFLAG =" EXITFLAG
end
phi1 = 1 - phi2;
xBL = 1/(1+(1-phi2)*ropoliol/(phi2*rohfo*r));
2 Comments
Answers (1)
Walter Roberson
on 12 Feb 2018
One of your global variables is probably not initialized, so it is probably empty.
You should avoid using global variables. You should https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
2 Comments
Walter Roberson
on 13 Feb 2018
Your code is suggestive that you are using ode45() or similar, which in turn would tend to suggest that T might start at 0. However, your function divides by T so Psat would have a divide by 0 there. The limit of fun() as T approaches 0 is undefined, being +inf on one side and -inf on the other. We therefore need to know what the valid range is for T to be able to solve this.
If you take your code and put in a symbolic T and symbolic x, then you can see that fun has an exp() in T with no x in it, and you can see that there are some terms in x and a term log(1-x) . For positive T < 22221/50 (about 444) the exp() term is real-valued and so cannot balance out the complex component of log(1-x) for x>1 . There just might be T values that exactly balance out the complex component for x>1 but if so they are very very narrow -- not zero crossings if they exist but rather just touching 0 with a jump of more than 1E41 for going even a hair over (arctan with a large multiplier changes quadrants)
For 0 < x < 1 then solutions can be found for up to about T = 444.4199999999522 with the top end seeming to be about x = .9999670374 . More typical solutions are for T roughly 225
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!