Comsol multiphysics; fzero and inline function with many parameters

In summary, to use the fzero function in COMSOL Multiphysics with more than two parameters, you need to pass the additional parameters as an anonymous function.
  • #1
hadoque
43
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
  • #2
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!
 
  • #3


Hello Johan,

It seems like you are trying to use the fzero function on an inline function with multiple parameters. This may not work because the fzero function is designed to find zeros for a single variable function, not a function with multiple variables.

One solution could be to define a new function that combines all the parameters into a single variable, and then use that function with the fzero function. For example:

myfun2 = @(x) myfun(x,2,1,0.3); % combining the parameters into a single variable
x1 = fzero(myfun2,-5);

Another option could be to use the fsolve function, which allows for multiple variables and parameters.

I hope this helps! Good luck with your research.
 

1. What is Comsol Multiphysics?

Comsol Multiphysics is a finite element analysis software used for modeling and simulating physical systems. It allows users to solve complex problems in various fields of physics such as heat transfer, electromagnetics, and fluid dynamics.

2. How does Comsol Multiphysics work?

Comsol Multiphysics uses a finite element method to break down a complex problem into smaller, simpler elements. These elements are then solved and combined to provide a solution for the entire system. It also includes a user-friendly interface and a wide range of built-in physics models and solvers.

3. What is fzero in Comsol Multiphysics?

fzero is a function in Comsol Multiphysics that is used for finding the root of a given equation. It uses a numerical method to calculate the value of the independent variable that makes the equation equal to zero.

4. How do you use inline functions with many parameters in Comsol Multiphysics?

To use inline functions with many parameters in Comsol Multiphysics, you can define the function in the Model Builder or in the Equation View. You can then use the function in your model by passing the required parameters as arguments.

5. Can Comsol Multiphysics handle parallel computing?

Yes, Comsol Multiphysics has the ability to distribute computations across multiple processors or cores, allowing for faster solving times. This feature is particularly useful for solving large and complex problems.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
12
Views
1K
  • Precalculus Mathematics Homework Help
Replies
6
Views
1K
  • Topology and Analysis
Replies
9
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
2K
Back
Top