Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
Can I set a variable equal to a function of itself?
Posted Mar 5, 2017, 1:00 p.m. EST Parameters, Variables, & Functions Version 5.2 6 Replies
Please login with a confirmed email address before reporting spam
A = a/(A+b)-c/(A+d)-e/(A+f)+g/(1+h/A).....
only A is unknown and other letters are constant.
As this is a non linear equation, I could not rearrange to make the RHS without A.
When I put A = a/(A+b)-c/(A+d)-e/(A+f)+g/(1+h/A) in the variable page, it shows 'circular variable dependency detected'.
Could anyone kindly help me to solve this problem?
Thank you
Please login with a confirmed email address before reporting spam
Thanks.
Please login with a confirmed email address before reporting spam
I'm not surprised that you can't specify a recursive assignment statement in the form of directly defining a variable in Comsol, but I'm curious about what other users may have to offer about other ways of accomplishing it. That said, I'm even more curious about *why* you want to do this. Would you care to share/explain your overall objective with the rest of us at this forum?
Thanks.
This is a biofilm model which consumes cellulose and produce H2. pH value would greatly affect the performance. The equation given above is used to calculate the pH. I built the model firstly on matlab. Matlab could solve this non linear equation by using fsolve. I am wondering how could I implement this in COMSOL.
Please login with a confirmed email address before reporting spam
There are several ways to deal with such situations. The one which seems to be closest too your case is described in this blog post : www.comsol.com/blogs/solving-algebraic-field-equations/
There are also a number of forum threads in which problems of circular dependencies are discussed, for example www.comsol.com/community/forums/general/thread/48995
Regards,
Henrik
Please login with a confirmed email address before reporting spam
I would suggest that you add a general form PDE Interface to
your model. Then set all coefficients to zero except of f.
f is specified like this:
f = A - a/(A+b)-c/(A+d)-e/(A+f)+g/(1+h/A)
so you need to solve this nonlinear implicit algebraic equation with
respect to the variable A.
As an initial value you can set zero, 2 or maybe an equation from an
analytical solution.
One year ago I also tried to solve this kind of equation with MATLAB and
fsolve. I didn't work that well. COMSOL is far better in that regard.
Please login with a confirmed email address before reporting spam
Kind regards,
Weiyi
Please login with a confirmed email address before reporting spam
Hello,
I would suggest that you add a general form PDE Interface to
your model. Then set all coefficients to zero except of f.
f is specified like this:
f = A - a/(A+b)-c/(A+d)-e/(A+f)+g/(1+h/A)
so you need to solve this nonlinear implicit algebraic equation with
respect to the variable A.
As an initial value you can set zero, 2 or maybe an equation from an
analytical solution.
One year ago I also tried to solve this kind of equation with MATLAB and
fsolve. I didn't work that well. COMSOL is far better in that regard.
I tried your method and I think it actually works!
Thank you very much.
Kind regards,
Weiyi
Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.
