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