



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




sfunc = ‘cos(x)./(x.^2 + 1)’
function y = mfunc(x) y = cos(x)./(x.^2 + 1)
fplot (sfunc, [dmin, dmax]) xzero = fzero (sfunc , x0)
xmin = fminbnd (sfunc, x1, x2)
fplot (mfunc , [dmin, dmax]) xzero = fzero (mfunc, x0) xmin = fminbnd (mfunc, x1, x2)
fplot (‘mfunc ’, [ dmin, dmax]) xzero = fzero (‘mfunc ’, x0) xmin = fminbnd (‘mfunc ’, x1, x2)
Errors
You must place quotes around m-file name
to correct…
String Function M-File Function
mfunc = inline(‘cos(x)./(x.^2 + 1’)
inline Function
fzero x = fzero (func_s, x0) x = fzero (‘func_m’, x0)
fminbnd x = fminbnd (func_s, x1, x2) x = fminbnd (‘func_m’, x1, x2)
quad, quadl A = quadl (func_s, x1,x2) A = quadl (‘func_m’, x1,x2)
trapz, diff No function in arguments No function in arguments
feval Cannot be used y = feval (‘func_m’, x)
eval y = eval (func_s) Cannot be used
fplot fplot (func_s, [-10 10]) fplot (‘func_m’, [-10 10])
Command String Function M-File Function
sfunc = ‘cos(x)./(x.^2+1)’
function y = mfunc(x) y = cos(x)./(x.^2+1)
The only Matlab command that will not work for the variable gen_func is eval.
eval can only be used with a string function feval can only be used with a m-file function
if func_type == 1 x = xmin ymin = eval(gen_func ) else ymin = feval(gen_fucn, xmin) end
Thus, anywhere in your code where you must evaluate the function at certain x values, you would have to incorporate the following condition …
Example: Determining y values at local minima
∆ → 0