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.

Matlab function with two output parameters under comsol

Please login with a confirmed email address before reporting spam

Hi, How can I use a MATLAB function with two output parameters in comsol. Matlab function : [y1, y2]=test(x) I can not get the values of y1 and y2 and distinguish the two variables under comsol to run my calculation. Infact, only one variable can be introduced


3 Replies Last Post 04.02.2019, 06:58 GMT-5
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 01.02.2019, 02:25 GMT-5

Hi

Calling MATLAB functions by the Comsol solvers only allow one output.

You need to split your functions into two. Alternatively you can do something like this

functions y=mytest(x,idx)

[y1,y2] = test(x); if idx==1 y = y1; else y = y2; end

If your function is very expensive to calculate then you'll have to cache the result of the calculaitons.

PS. Note that using "test" as a function name in Comsol will probably cause problems for your model.

-------------------
Lars Gregersen
Comsol Denmark
Hi Calling MATLAB functions by the Comsol solvers only allow one output. You need to split your functions into two. Alternatively you can do something like this functions y=mytest(x,idx) [y1,y2] = test(x); if idx==1 y = y1; else y = y2; end If your function is very expensive to calculate then you'll have to cache the result of the calculaitons. PS. Note that using "test" as a function name in Comsol will probably cause problems for your model.

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 01.02.2019, 05:01 GMT-5

Hi

Calling MATLAB functions by the Comsol solvers only allow one output.

You need to split your functions into two. Alternatively you can do something like this

functions y=mytest(x,idx)

[y1,y2] = test(x); if idx==1 y = y1; else y = y2; end

If your function is very expensive to calculate then you'll have to cache the result of the calculaitons.

PS. Note that using "test" as a function name in Comsol will probably cause problems for your model.

Thank you Lars Gregersen for your answer, regarding the name of the function I just use "test" as an example.

functions y=mytest(x,idx)

[y1,y2] = test(x); if idx==1 y = y1; else y = y2; end

In your proposal, I can only use one variable in comsol y1 or y2. I need both variables at the same time to start the calculation.

Best regards

>Hi > >Calling MATLAB functions by the Comsol solvers only allow one output. > >You need to split your functions into two. Alternatively you can do something like this > >functions y=mytest(x,idx) > >[y1,y2] = test(x); >if idx==1 >y = y1; >else >y = y2; >end > >If your function is very expensive to calculate then you'll have to cache the result of the calculaitons. > >PS. Note that using "test" as a function name in Comsol will probably cause problems for your model. Thank you Lars Gregersen for your answer, regarding the name of the function I just use "test" as an example. functions y=mytest(x,idx) [y1,y2] = test(x); if idx==1 y = y1; else y = y2; end In your proposal, I can only use one variable in comsol y1 or y2. I need both variables at the same time to start the calculation. Best regards

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 04.02.2019, 06:58 GMT-5

Let's says you have the expression "y1+y2" somewhere.

Using the function definitions above you'll then have to use this expression instead: "mytest(x,1)+mytest(x,2)"

-------------------
Lars Gregersen
Comsol Denmark
Let's says you have the expression "y1+y2" somewhere. Using the function definitions above you'll then have to use this expression instead: "mytest(x,1)+mytest(x,2)"

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.