MATLAB files can be flexible when they are combined with the use of anonymous functions. Anonymous functions can also be supplied as parameters to anonymous functions. The example given can be handled with simple nesting:
f1 = @(x)[x -x sin(x)]
f2 = @(x)x'*x;
g = @(x)f2(f1(x));
r = integral (g, 0, 1, 'ArrayValued', true);
More cleverness may be required in some cases, I guess. You can extend f2 to accept multiple inputs based on x or nest deeper, constructing what amounts to an evaluation tree to minimize redundant computations. -- Mike
1 Comment
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/73119-anonymous-functions-and-integration#comment_144765
Direct link to this comment
https://au.mathworks.com/matlabcentral/answers/73119-anonymous-functions-and-integration#comment_144765
Sign in to comment.