Finding Roots of Functions with Matlab

AI Thread Summary
To find the roots of functions in Matlab using methods like bisection and secant, the user is struggling with the exponential function F(x)=e^{-0.5x}(4-x)-2. While they successfully entered a polynomial function using a row vector, they are unsure how to represent the exponential function. The user encountered issues with the feval function, receiving an error that suggests the argument must be a string or function handle, and they are questioning the validity of using polyval for non-polynomial functions. A suggested solution is to use anonymous functions in Matlab, which can simplify function evaluation for iterative methods. Understanding how to properly define and use these functions is crucial for successfully finding roots in Matlab.
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.
 
Back
Top