How do I merge function handles?

suppose I have 2 function handles to evaluate
for i=1:90
f= @(x)x^3*sin(i)
and
g=@(x)x^2*cos(i)
end
the functions i have are far more complicated. now suppose i want to merge them to obtain f+g, i.e. a single function
@(x)x^3sin(i)+x^2cos(i).
How can i do that without combining the expressions but only using f and g?
thanks for the help

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 5 月 11 日

2 投票

@(x) f(x) + g(x)
In some cases, you can use
syms x
matlabFunction( f(x) + g(x), 'vars', x)
If there are no captured variables, then you can use string manipulation on char() of the handles.

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

質問済み:

2016 年 5 月 11 日

回答済み:

2016 年 5 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by