In this example we find some roots of several functions 1 Find the root of sin x near x 3 This should be Note an initial value or guess is needed to start this iteration In this case the starting value is 3 x fzero sin 3 x 3 1416 Well this was easy Note that the sin function is already defined What if the function is not already defined in Matlab In this case we make and save it ourselves For example suppose we want to solve for the value of x that would satisfy the equation sin x e x 5 This is the same as finding a root of sin x e x 5 0 First write and save the following as an m file called sss m function f sss x sss computes f sin x exp x 5 calling syntax f sss x f sin x exp x 5 Now it is easy to find the root make sure the path of Matlab can see where this script or m file is stored x fzero sss 1 initial guess at root is x 1 x 1 7878 Next we plot the function to see where the root s really are x 3 01 3 y sss x plot x y grid 5 0 5 10 15 3 2 1 0 1 2 3
View Full Document