fminsearch, Function arguments must be symbolic variables, and function body must be sym expression.

Hi All, my code is:
p=10;
spdf = @(x) 3.*(50.^3)./(x+50).^(3+1)./(1-(50./(50+50)).^3);
fun2 = @(x,z) min(x,max(0,fzero(@(y) (100-p-x+y).^(-1)-(2.*z(2)+4.*z(1).*y).^2,0))).^2.*spdf(x);
fun3 = @(z) integral(@(x) fun2(x,z),0,50,'arrayvalued', true);
fun21 = @(x,z) min(x,max(0,fzero(@(y) (100-p-x+y).^(-1)-(2.*z(2)+4.*z(1).*y).^2,0))).*spdf(x);
fun31 = @(z) integral(@(x) fun21(x,z),0,50,'arrayvalued', true);
funfun(z)=@(z) abs((fun31(z)-10).*(fun3(z)-178.57145));
fminsearch(funfun(z),[0.002,0.04])
The error is:
Error using sym/subsindex (line 836)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Anyone can help me fix my code? Anyhelp is appreciated!

 Accepted Answer

funfun = @(z) abs((fun31(z)-10).*(fun3(z)-178.57145));
% ^----removed it
fminsearch(funfun,[0.002,0.04])

1 Comment

P.S - It takes ~39 seconds to evaluate. I have no idea what your trying to evaluate.
But for sure the result obtained is
ans =
0.0015 0.0003

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!