Finding Roots of Functions with Matlab

Click For Summary
SUMMARY

The discussion focuses on finding roots of functions using the bisection and secant methods in MATLAB. The user is specifically trying to implement the function F(x)=e^{-0.5x}(4-x)-2 and is encountering difficulties with the exponential term. They successfully used the polynomial function F(x)=0.95x^{3}-5.9x^{2}-6 but are unsure about the applicability of the polyval function for non-polynomial functions. The solution involves using anonymous functions in MATLAB for better function evaluation.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of numerical methods such as bisection and secant methods
  • Knowledge of function handles and anonymous functions in MATLAB
  • Basic understanding of exponential functions
NEXT STEPS
  • Learn how to implement anonymous functions in MATLAB
  • Research the use of feval for function evaluation in MATLAB
  • Explore the bisection and secant methods for root-finding in MATLAB
  • Study the differences between polyval and inline functions in MATLAB
USEFUL FOR

Students and professionals working with MATLAB who need to find roots of complex functions, particularly those involving exponential terms, as well as anyone looking to enhance their understanding of numerical methods in programming.

yohak
Messages
4
Reaction score
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 F(x)=e^{-0.5x}(4-x)-2 into Matlab. I had no problem with F(x)=0.95x^{3}-5.9x^{2}-6 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 F(x)=0.95x^{3}-5.9x^{2}-6 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: F(x)=0.95x^{3}-5.9x^{2}-6 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
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
2
Views
2K
Replies
2
Views
3K