Finding Roots of Functions with Matlab

In summary, the person is having trouble with using the bisection method and secant method in Matlab to find the roots of functions. They have successfully written m-files for some functions, but are struggling with implementing the function F(x)=e^{-0.5x}(4-x)-2 due to the presence of an exponential term. They have also encountered issues with using the feval function, but have found a workaround using polyval. They are not sure if this will work for all functions and are looking for a simpler solution using inline functions. They suggest using anonymous functions as a possible solution.
  • #1
yohak
4
0

Homework Statement


I need to find the roots of some functions using the bisection method, secant method, etc in Matlab. I have the m-files written, but I'm having trouble putting the function [tex]F(x)=e^{-0.5x}(4-x)-2[/tex] into Matlab. I had no problem with [tex]F(x)=0.95x^{3}-5.9x^{2}-6[/tex] but I don't know what to do about the exponential.

I'm also having trouble getting feval to work. I got around it by using polyval, but although it works for [tex]F(x)=0.95x^{3}-5.9x^{2}-6[/tex] I don't know if it will work for every function.

Homework Equations


none


The Attempt at a Solution


I'm kind of new to Matlab, but I understand that polynomials are entered as a single row vector (example: [tex]F(x)=0.95x^{3}-5.9x^{2}-6[/tex] is entered as [0.95 -5.9 0 -6]) but I don't know how to put this function in since it is an exponential.

Is polyval a valid solution to the feval issue? The error says "Argument must contain a string or function_handle" but I don't know what that means.
 
Physics news on Phys.org
  • #3
You could create an anonymous function, e.g.:
Code:
f = @([I]arg_list[/I]) [I]expression[/I];
where arg_list are the function arguments and expression is the function, and f is the name of the anon function.
 

FAQ: Finding Roots of Functions with Matlab

What is the purpose of finding roots of functions with Matlab?

Finding roots of functions with Matlab is an important tool in numerical analysis and mathematical modeling. It allows us to determine the values of the independent variable where the function is equal to zero, which can provide valuable insights into the behavior of a system or function.

How does Matlab find the roots of a function?

Matlab uses a variety of numerical methods to find the roots of a function, including the bisection method, Newton-Raphson method, and secant method. These methods involve iteratively approximating the roots of a function until a desired level of accuracy is achieved.

Can Matlab find complex roots of a function?

Yes, Matlab is capable of finding both real and complex roots of a function. It uses the same numerical methods for finding complex roots as it does for real roots.

What happens if a function has multiple roots?

If a function has multiple roots, Matlab will return all of the roots it finds. However, it is important to note that some numerical methods may have difficulty finding all of the roots, especially if they are very close together or if the function is highly nonlinear.

Are there any limitations to finding roots of functions with Matlab?

While Matlab is a powerful tool for finding roots of functions, it does have some limitations. It may have difficulty finding roots for highly nonlinear functions or functions with discontinuities. Additionally, the accuracy of the results may be affected by the choice of numerical method and the initial guess for the root.

Similar threads

Replies
1
Views
932
Replies
3
Views
1K
Replies
10
Views
2K
Replies
1
Views
1K
Replies
1
Views
1K
Replies
1
Views
1K
Back
Top