matlab - Matrix multiplication of a Array Cell of function handle -
i have built cell array of function_ handles below:
b = {@(x) x(1)+x(2)^2 @(x) x(1)-2*x(2)} assume a = [1 2; 3 4]. need perform matrix multiplication a*b have cell array
a*b = {@(x) x(1)+x(2)^2 + 2*(x(1)-2*x(2)) @(x) 3*(x(1)+x(2)^2) + 4*(x(1)-2*(x(2))} how can this?
it relatively easy if have access symbolic toolbox:
c=regexprep(cellfun(@func2str, b, 'uni', 0), '@\(x\)', ''); f=arrayfun(@(d) ['@(x) ', char(d)], sym(a)*sym(c), 'uni', 0); this returns
>> f f = '@(x) 3*x(1) - 4*x(2) + x(2)^2' '@(x) 7*x(1) - 8*x(2) + 3*x(2)^2' note symbolic manipulation simplies result.
Comments
Post a Comment