"Looks likes I am not allowed to do that . I would like to know how this can be achieved"
Your attempted code has several bugs in it, e.g.:
- g(t) is not a valid output argument.
- g = @(T) is not a valid anonymous function.
- you do not define the output arguments a0,a1,a2.
- a2*T^2 + a1*T + a0 is not assigned to anything, so its result is discarded.
- a2*T^2 + a1*T + a0 is not "...based on equation g(t) = a0 + a1* t^2+ a2* t^3."
- probably others, I gave up checking at that point.
A function handle is a variable just like any other, it can be returned just like any other variable, e.g.
function out = myfun()
out = @sin;
>> f = myfun();
ans = 1
"The polynomial g(t) needs be calculated at time t =T , based on equation g(t) = a0 + a1* t^2+ a2* t^3."
For that you do not need to return a function handle. you can just calculate the value directly and return that:
function g = fcn(s,v,a,t)
a0 = ..;
a1 = ..;
a2 = ..;
g = a0 + a1.*t.^2+ a2.*t.^3;