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?

Please login with a confirmed email address before reporting spam

I got a variable A and it's in this kind of form,
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

6 Replies Last Post Mar 6, 2017, 6:21 p.m. EST
Robert Koslover Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Mar 5, 2017, 3:15 p.m. EST
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.
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.

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Mar 5, 2017, 3:23 p.m. EST

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.

[QUOTE] 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. [/QUOTE] 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.

Henrik Sönnerlind COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Mar 6, 2017, 1:30 a.m. EST
Hi,

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
Hi, 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 : https://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 https://www.comsol.com/community/forums/general/thread/48995 Regards, Henrik

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Mar 6, 2017, 2:43 a.m. EST
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.
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.

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Mar 6, 2017, 6:20 p.m. EST
Thank you so much for your links. They help a lot!

Kind regards,

Weiyi
Thank you so much for your links. They help a lot! Kind regards, Weiyi

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Mar 6, 2017, 6:21 p.m. EST

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
[QUOTE] 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. [/QUOTE] 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.