Assume that the function y(x) = f (x) + g(x) has a single local minimum in the
interval 0 <= x <= 1, at x = xm. Write
(i) a function M-file (called funct.m) and
(ii) a MATLAB statement (using the fminbnd command)
that together will compute xm and the value of y at xm.
i)
Matlab function code('func.m'):
function fun = func (x)
"\\mathrm{f}=@(\\mathrm{x}) \\mathrm{x}^3 ;" g=@(x) 2^{*} x+1 ;
"fun =f(x)-g(x);"
end
ii) Main Program:
"\\mathrm{clc}"
"\\mathrm{f}=@(\\mathrm{x}) func (\\mathrm{x}) ;"
"c=f z e r o(f,-1) ;"
fprintf('The zero of the function is, c=% 4.2f \n', c);
Output:
Comments
Leave a comment