How can i make a changeable function input in a matlab function.

I got this function made to calculate the radical of a standard function f(x)=x^4-x-3 and works fine.. But i want to know if its possible to make my f(x) changeable some way, so i can use this function to calculate any f(x) type.
function xi = midpointf(a,b,N)
ai(1)=a; bi(1)=b;
for i=2:N+1;
xi=(ai(i-1)+bi(i-1))/2;
fx=xi^4-xi-3;
fa=ai(i-1)^4-ai(i-1)-3;
if fx==0
'radical'
xi
elseif fx*fa >0
ai(i)=xi; bi(i)=bi(i-1);
else
ai(i)=ai(i-1); bi(i)=xi;
end
end
'radical'
xi

 採用された回答

Sean de Wolski
Sean de Wolski 2013 年 11 月 8 日

0 投票

3 件のコメント

pan
pan 2013 年 11 月 8 日
you mean i should create a handle before running the function and use the handle as an input, right?
Sean de Wolski
Sean de Wolski 2013 年 11 月 8 日
Yup!
Pass in the function handle and then your solver above will do the same set of instructions on it regardless of what it's actually calculating.
pan
pan 2013 年 11 月 8 日
It worked fine, ty! :) I knew about handle but didn't know how to use it properly :P Had to read more careful.. thanks again

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

質問済み:

pan
2013 年 11 月 8 日

コメント済み:

pan
2013 年 11 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by