我无法打印出 h_a_b。我能够得到函数 f 和 g 但不是这个。我需要使用 h_a_b 函数,所以我可以做 h(f(x),g(x)) 并计算 h(a,b) 的 sqrt。见方程
我总是收到这个错误
Undefined function 'h_a_b' for input arguments of type 'function_handle'.
我想编写一个程序来创建代表函数的 3 个匿名函数
需要的方程
f(x) = 10*cos x ,
g(x) = 5*sin * x,并且
h(a,b) = \sqrt(a^2 + b^2)。
这是我的代码
f = @ (x) 5*sin(x);
g = @ (x) 10*cos(x);
h_a_b = @ (a,b) sqrt(a.^2 + b.^2);
然后我用给我的这个函数来绘制它。
function plotfunc(fun,points)
%PLOTFUNC Plots a function between the specified points.
% Function PLOTFUNC accepts a function handle, and
% plots the function at the points specified.
% Define variables:
% fun -- Function handle
% msg -- Error message
%
msg = nargchk(2,2,nargin);
error(msg);
% Get function name
fname = func2str(fun);
% Plot the data and label the plot
plot(points,fun(points));
title(['\bfPlot of ' fname '(x) vs x']);
xlabel('\bfx');
ylabel(['\bf' fname '(x)']);
grid on;
end