how to pass inline function in a M-file function (user defined)

2 views (last 30 days)
function out = convert(f(t),t,th)
if(th==1)
out=f(1);
return
else
out=f(th).*convert(f(t),t,th-1);
return
end
end
"in the command window"
t=[1:1:10];
f=inilne('sin(t)','t');
out=convert('f(t)','t',4);

Answers (1)

Walter Roberson
Walter Roberson on 26 Mar 2012
function out = convert(f,t,th)
if th == 1
out = f(1);
return
else
out = f(th) .* convert(f, t, th-1);
return
end
end
In the command window,
t = [1:1:10];
f = inline('sin(t)', 't');
out = convert(f, t, 4);
Note: your convert() function never uses the value of t, so you might as well not pass it around.
I don't know why you want to be taking sin(1) ?
I am wondering if in convert(), instead of out=f(1) you want out=f(t) ?

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!