Comsol multiphysics; fzero and inline function with many parameters

Click For Summary
The discussion revolves around using COMSOL Multiphysics to define an inline function with multiple parameters and applying the fzero function to it. The original poster successfully created a function with two parameters but encountered an error when attempting to include a fourth parameter, receiving a message about too few arguments. A solution was provided, suggesting the use of an anonymous function to pass the additional parameters to fzero. This approach allows for the correct execution of the function with all required parameters, resolving the issue.
hadoque
Messages
39
Reaction score
1
Hi
I'm trying to get comsol multiphysics to first define an inline
function with 1 variable and 4 parameters, and then run fzero on that
same function. I can do it with two parameters, but no moore.

This works:

Code:
clear
myfun=inline('exp(y).*cos(x)+z', 'x', 'y', 'z');
x1 = fzero(myfun,-5,2,1)

This does not work:

Code:
clear
myfun=inline('exp(y).*cos(x)+z+u', 'x', 'y', 'z', 'u');
x1 = fzero(myfun,-5,2,1,0.3)

C» test
Error: Too few arguments to inline function.


Would be thankful for any hints about this.


/Johan
 
Physics news on Phys.org
Hi Johan,
I had a similar issue when trying to use the fzero function in COMSOL Multiphysics. It seems that you need to pass the additional parameter as an anonymous function. Try this:

clear
myfun=inline('exp(y).*cos(x)+z+u', 'x', 'y', 'z', 'u');
x1 = fzero(@(x) myfun(x,-5,2,1,0.3),-5)

Hope this helps!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
1K
Replies
7
Views
9K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
Replies
3
Views
2K