フィルターのクリア

How do you create a composite function in matlab?

29 ビュー (過去 30 日間)
Buttercup12
Buttercup12 2021 年 2 月 28 日
コメント済み: Walter Roberson 2023 年 5 月 2 日
If I have two functions, like
function a=func1(x)
and
function b=func2(q,p)
as examples. Is it possible to combine them to create a composite function like func1(func2(q)) = func1∘func2(q), and if so how do you do that?
  3 件のコメント
Torsten
Torsten 2023 年 5 月 2 日
syms x
f(x) = ...;
g(x) = ...;
h1(x) = f(g(x))
h2(x) = g(f(x))
Walter Roberson
Walter Roberson 2023 年 5 月 2 日
Note: MATLAB does not have any explicit function-composition operator . For example Maple would allow you to write func1@func2(q) but MATLAB does not have any support for such an operator.
MATLAB does allow you to define
func1_o_func2 = @(x) func1(func2(x))
fplot(func1_o_func2, [-5 5]) %for example

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2021 年 2 月 28 日
f = @sin;
g = @cos;
% define it two different ways
fg = @(x) f(g(x));
h = @(x) sin(cos(x));
% Compare the two approaches
x = 0:0.1:2*pi;
max(abs(fg(x)-h(x)))
ans = 0
Or you could write a function file.
function y = myfun3(x)
y = func1(func2(x, 3)); % fixing p = 3
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by