How can I pass a anonymous function as an output to another function?
Show older comments
function [a0,a1,a2]= fcn(s,v,a,T)
%a0,a1,a2 are coefficients of a polynomial which are calculated based on inputs s,v,a,T
end
The above function returns coefficients. The polynomial g(t) needs be calculated at time t =T , based on equation g(t) = a0 + a1* t^2+ a2* t^3.
for doing this I have added the following lines to the function above
function [a0,a1,a2]= fcn(s,v,a,T)
%a0,a1,a2 are coefficients of a polynomial which are calculated based on inputs s,v,a,T
g = @(T)
a2*T^2 + a1*T + a0
g(T)
end
But I am unable to pass g(t) as output to the function fcn as shown below:
function [a0,a1,a2,g(t)]= fcn(s,v,a,T)
%a0,a1,a2 are coefficients of a polynomial which are calculated based on inputs s,v,a,T
g = @(T)
a2*T^2 + a1*T + a0
g(T)
end
Looks likes I am not allowed to do that . I would like to know how this can be achieved
Note: If I just use g in the output array, it doesn't return the g(T) value instead it returns a2*T^2 + a1*T + a0 because g is a function handle.
Accepted Answer
More Answers (0)
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!