Finding Roots of Functions with 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 [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
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