How can I pass a anonymous function as an output to another function?
显示 更早的评论
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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!