My code is:
p=0.51:0.001:1.013; fun1 = @(x) x.^2.*exp(-x)./(1-exp(-10)); fun2 = @(x,u) fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10]).^2.*exp(-x)./(1-exp(-10)); fun3 = @(u) integral(@(x) fun1(x),0,0.5./(20-p)^0.5./(2.*u))+integral(@(x) fun2(x,u),0.5./(20-p)^0.5./(2.*u),10,'arrayvalued', true); fun11 = @(x) x.*exp(-x)./(1-exp(-10)); fun21 = @(x,u) fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10]).*exp(-x)./(1-exp(-10));fun31 = @(u) integral(@(x) fun11(x),0,0.5./(20-p)^0.5./(2.*u))+integral(@(x) fun21(x,u),0.5./(20-p)^0.5./(2.*u),10,'arrayvalued', true);fun4 = @(x,u) (20-x+fzero(@(y) 2.*u.*y.*(20-p-x+y).^0.5-0.5,[0,10])-p)^0.5.*exp(-x)./(1-exp(-10)); fun44= @(u) integral(@(x) (20-p).^0.5.*exp(-x)./(1-exp(-10)),0,0.5./(20-p)^0.5./(2.*u))+integral(@(x) fun4(x,u),0.5./(20-p)^0.5./(2.*u),10,'arrayvalued', true);fun51 =@(p) p - feval(fun31,fzero(@(u) fun3(u)-0.9973,[0.02,1])); fun52 =@(p) feval(fun44,fzero(@(u) fun3(u)-0.9973,[0.02,1])) - integral(@(x) (20-x).^0.5.*exp(-x)./(1-exp(-10)),0,10);plot3(p,fun51(p),fun52(p))format long
Here is the error I get:
FZERO cannot continue because user-supplied function_handle ==> @(u)fun3(u)-0.9973 failed with the error below.
One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power.
I am sorry that my function is a little bit messy. But I am worried about that you may miss some information if I simplify it. Any help is appreciated, thanks!
Best Answer