The array returned by a function changed size between calls










1















I'm trying to solve for an array of values as explained in the following code. But I get this error:



Traceback (most recent call last):

File "<ipython-input-842-cf2c76a38adb>", line 25, in <module>
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 148, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 227, in _root_hybr
ml, mu, epsfcn, factor, diag)

ValueError: The array returned by a function changed size between calls


It's not shown in the code but T is a 500 elements array previously solved for.



P = 5000

x1 = np.linspace(0.1,1,500)
x2 = 1-x1

def VLE_2(y1,x1,T):
y2=1-y1
tau12 = a12+b12/T
tau21 = a21+b21/T
G12 = np.exp(-0.4*tau12)
G21 = np.exp(-0.4*tau21)
gamma_1 = np.exp((x2**2)*((tau21*G21**2)/(x1+x2*G21)**2+(tau12*G12)/(x2+x1*G12)**2))
gamma_2 = np.exp((x1**2)*((tau12*G12**2)/(x2+x1*G12)**2+(tau21*G21)/(x1+x2*G21)**2))
Psat1 = np.exp((106.1)-7614.8/T-12.686*np.log(T)+1.0733e-5*T**2)
Psat2 = np.exp((84.912)-6722.2/T-9.5157*np.log(T)+7.2244e-6*T**2)
#sol = np.zeros(2)
return y1*P - x1*gamma_1*Psat1


y1 = np.ones(500)
guess = 0.9

for i in range(0,500):
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))









share|improve this question
























  • Im using Python 3 btw.

    – reyPanda
    Nov 15 '18 at 6:22











  • Please add the full error traceback to your question.

    – Klaus D.
    Nov 15 '18 at 6:29











  • Edit your question and add it there as code-formatted text!

    – Klaus D.
    Nov 15 '18 at 6:33











  • @KlausD. Thanks for the feedback!

    – reyPanda
    Nov 15 '18 at 6:37






  • 1





    I solved it. Thanks everyone for the input. I have to make x2 part of the function... 'VLE_2(y1,x1,x2,T)' otherwise its solving for one value of y per each x1,T but multiple x2 which would return an array of a different size than needed.

    – reyPanda
    Nov 15 '18 at 8:09















1















I'm trying to solve for an array of values as explained in the following code. But I get this error:



Traceback (most recent call last):

File "<ipython-input-842-cf2c76a38adb>", line 25, in <module>
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 148, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 227, in _root_hybr
ml, mu, epsfcn, factor, diag)

ValueError: The array returned by a function changed size between calls


It's not shown in the code but T is a 500 elements array previously solved for.



P = 5000

x1 = np.linspace(0.1,1,500)
x2 = 1-x1

def VLE_2(y1,x1,T):
y2=1-y1
tau12 = a12+b12/T
tau21 = a21+b21/T
G12 = np.exp(-0.4*tau12)
G21 = np.exp(-0.4*tau21)
gamma_1 = np.exp((x2**2)*((tau21*G21**2)/(x1+x2*G21)**2+(tau12*G12)/(x2+x1*G12)**2))
gamma_2 = np.exp((x1**2)*((tau12*G12**2)/(x2+x1*G12)**2+(tau21*G21)/(x1+x2*G21)**2))
Psat1 = np.exp((106.1)-7614.8/T-12.686*np.log(T)+1.0733e-5*T**2)
Psat2 = np.exp((84.912)-6722.2/T-9.5157*np.log(T)+7.2244e-6*T**2)
#sol = np.zeros(2)
return y1*P - x1*gamma_1*Psat1


y1 = np.ones(500)
guess = 0.9

for i in range(0,500):
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))









share|improve this question
























  • Im using Python 3 btw.

    – reyPanda
    Nov 15 '18 at 6:22











  • Please add the full error traceback to your question.

    – Klaus D.
    Nov 15 '18 at 6:29











  • Edit your question and add it there as code-formatted text!

    – Klaus D.
    Nov 15 '18 at 6:33











  • @KlausD. Thanks for the feedback!

    – reyPanda
    Nov 15 '18 at 6:37






  • 1





    I solved it. Thanks everyone for the input. I have to make x2 part of the function... 'VLE_2(y1,x1,x2,T)' otherwise its solving for one value of y per each x1,T but multiple x2 which would return an array of a different size than needed.

    – reyPanda
    Nov 15 '18 at 8:09













1












1








1








I'm trying to solve for an array of values as explained in the following code. But I get this error:



Traceback (most recent call last):

File "<ipython-input-842-cf2c76a38adb>", line 25, in <module>
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 148, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 227, in _root_hybr
ml, mu, epsfcn, factor, diag)

ValueError: The array returned by a function changed size between calls


It's not shown in the code but T is a 500 elements array previously solved for.



P = 5000

x1 = np.linspace(0.1,1,500)
x2 = 1-x1

def VLE_2(y1,x1,T):
y2=1-y1
tau12 = a12+b12/T
tau21 = a21+b21/T
G12 = np.exp(-0.4*tau12)
G21 = np.exp(-0.4*tau21)
gamma_1 = np.exp((x2**2)*((tau21*G21**2)/(x1+x2*G21)**2+(tau12*G12)/(x2+x1*G12)**2))
gamma_2 = np.exp((x1**2)*((tau12*G12**2)/(x2+x1*G12)**2+(tau21*G21)/(x1+x2*G21)**2))
Psat1 = np.exp((106.1)-7614.8/T-12.686*np.log(T)+1.0733e-5*T**2)
Psat2 = np.exp((84.912)-6722.2/T-9.5157*np.log(T)+7.2244e-6*T**2)
#sol = np.zeros(2)
return y1*P - x1*gamma_1*Psat1


y1 = np.ones(500)
guess = 0.9

for i in range(0,500):
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))









share|improve this question
















I'm trying to solve for an array of values as explained in the following code. But I get this error:



Traceback (most recent call last):

File "<ipython-input-842-cf2c76a38adb>", line 25, in <module>
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 148, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)

File "/anaconda3/lib/python3.6/site-packages/scipy/optimize/minpack.py", line 227, in _root_hybr
ml, mu, epsfcn, factor, diag)

ValueError: The array returned by a function changed size between calls


It's not shown in the code but T is a 500 elements array previously solved for.



P = 5000

x1 = np.linspace(0.1,1,500)
x2 = 1-x1

def VLE_2(y1,x1,T):
y2=1-y1
tau12 = a12+b12/T
tau21 = a21+b21/T
G12 = np.exp(-0.4*tau12)
G21 = np.exp(-0.4*tau21)
gamma_1 = np.exp((x2**2)*((tau21*G21**2)/(x1+x2*G21)**2+(tau12*G12)/(x2+x1*G12)**2))
gamma_2 = np.exp((x1**2)*((tau12*G12**2)/(x2+x1*G12)**2+(tau21*G21)/(x1+x2*G21)**2))
Psat1 = np.exp((106.1)-7614.8/T-12.686*np.log(T)+1.0733e-5*T**2)
Psat2 = np.exp((84.912)-6722.2/T-9.5157*np.log(T)+7.2244e-6*T**2)
#sol = np.zeros(2)
return y1*P - x1*gamma_1*Psat1


y1 = np.ones(500)
guess = 0.9

for i in range(0,500):
y1[i] = fsolve(VLE_2,guess,args=(x1[i],T[i]))






python python-3.x numpy scipy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 6:33









Blckknght

64.9k559108




64.9k559108










asked Nov 15 '18 at 6:21









reyPandareyPanda

77




77












  • Im using Python 3 btw.

    – reyPanda
    Nov 15 '18 at 6:22











  • Please add the full error traceback to your question.

    – Klaus D.
    Nov 15 '18 at 6:29











  • Edit your question and add it there as code-formatted text!

    – Klaus D.
    Nov 15 '18 at 6:33











  • @KlausD. Thanks for the feedback!

    – reyPanda
    Nov 15 '18 at 6:37






  • 1





    I solved it. Thanks everyone for the input. I have to make x2 part of the function... 'VLE_2(y1,x1,x2,T)' otherwise its solving for one value of y per each x1,T but multiple x2 which would return an array of a different size than needed.

    – reyPanda
    Nov 15 '18 at 8:09

















  • Im using Python 3 btw.

    – reyPanda
    Nov 15 '18 at 6:22











  • Please add the full error traceback to your question.

    – Klaus D.
    Nov 15 '18 at 6:29











  • Edit your question and add it there as code-formatted text!

    – Klaus D.
    Nov 15 '18 at 6:33











  • @KlausD. Thanks for the feedback!

    – reyPanda
    Nov 15 '18 at 6:37






  • 1





    I solved it. Thanks everyone for the input. I have to make x2 part of the function... 'VLE_2(y1,x1,x2,T)' otherwise its solving for one value of y per each x1,T but multiple x2 which would return an array of a different size than needed.

    – reyPanda
    Nov 15 '18 at 8:09
















Im using Python 3 btw.

– reyPanda
Nov 15 '18 at 6:22





Im using Python 3 btw.

– reyPanda
Nov 15 '18 at 6:22













Please add the full error traceback to your question.

– Klaus D.
Nov 15 '18 at 6:29





Please add the full error traceback to your question.

– Klaus D.
Nov 15 '18 at 6:29













Edit your question and add it there as code-formatted text!

– Klaus D.
Nov 15 '18 at 6:33





Edit your question and add it there as code-formatted text!

– Klaus D.
Nov 15 '18 at 6:33













@KlausD. Thanks for the feedback!

– reyPanda
Nov 15 '18 at 6:37





@KlausD. Thanks for the feedback!

– reyPanda
Nov 15 '18 at 6:37




1




1





I solved it. Thanks everyone for the input. I have to make x2 part of the function... 'VLE_2(y1,x1,x2,T)' otherwise its solving for one value of y per each x1,T but multiple x2 which would return an array of a different size than needed.

– reyPanda
Nov 15 '18 at 8:09





I solved it. Thanks everyone for the input. I have to make x2 part of the function... 'VLE_2(y1,x1,x2,T)' otherwise its solving for one value of y per each x1,T but multiple x2 which would return an array of a different size than needed.

– reyPanda
Nov 15 '18 at 8:09












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313551%2fthe-array-returned-by-a-function-changed-size-between-calls%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313551%2fthe-array-returned-by-a-function-changed-size-between-calls%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo