Selecting on function from an array of anonymous functions
古いコメントを表示
I have an array of 3 anonymous functions where the user is asked to select one of the three functions. It choses which function with a number of variables that passes it to the function bisect that will approximate the roots of the function. If I type the actual equation and the variables into the function bisect it works. If I pass it through a seperate .m file as I am doing here, it gives me the error:
Undefined operator '^' for input arguments of type 'cell'.
Error in Q2a>@(x)x^3-5*cos(x/2)
Error in bisect (line 15)
fa = f(a);
Error in Q2a (line 15)
bisect(f, x0(1), x1(1), nmax, eps, printflag)
where Q2a is the .m file with the folling code. How can I make this work?
eq_array = {@(x)x.^3-5*cos(x/2),@(x)tan(x/2)-x,@(x)43*x*log(x)-2*x.^2};
x0={0.5 1 75};
x1={4 3 125};
eps={0.5e-7 0.5e-9 0.5e-7};
prompt=('Which equation do you want to evalute? (1,2 or 3): ');
eq=input(prompt);
f=eq_array(eq);
x0=x0_array(eq);
x1=x1_array(eq);
nmax=40;
eps=0.5e-7;
prinflag=1;
bisect(f, x0, x1, nmax, eps, printflag)
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!