A function handle constructed by a symbolic function and another function handle

2 ビュー (過去 30 日間)
Hello,
I have a simple problem but unfortunately could not figure out how to fix it. Consider the following
syms sigma(x)
par=sym('par', [1 2]);
sigma(x)=par(1)+par(2)*x;
f=@(x)x;
Now, imagine I want to construct a function handle H using f and sigma as bellow:
sigma = matlabFunction(sigma);
H = @(x,par) sigma(x,par)+f(x);
Now, you see my problem. For matlab H has 2 inputs: x and par. But, I am struggling to define H(x,par(1),par(2)) = sigma(x,par(1),par(2))+f(x)
Thanks for your help in advance!
Babak

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 6 日
You can do this without symbolic variables.
The definition is correct, just call the function with appropriate inputs -
sigma = @(x,par) par(1)+par(2)*x;
f=@(x)x;
H = @(x,par) sigma(x,par)+f(x)
H = function_handle with value:
@(x,par)sigma(x,par)+f(x)
H(1,[1 2])
ans = 4
  4 件のコメント
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2023 年 10 月 6 日
This is a wonderful answer!
Thanks for your great help!
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 6 日
You are welcome!
Glad to have helped :)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by