fsolve, In an assignment A(:) = B, the number of elements in A and B must be the same.

20 views (last 30 days)
Hi All, my code is:
format long;
pvals = 10:0.2:14;
nump = length(pvals);
m = zeros(1, nump);n = zeros(1, nump);z = zeros(1, nump);
for pidx = 1 : nump
p = pvals(pidx);
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).*(2.*z(2)+4.*z(1).*y).^2-1,1E-6))).^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).*(2.*z(2)+4.*z(1).*y).^2-1,1E-6))).*spdf(x);
fun31 = @(z) integral(@(x) fun21(x,z),0,50,'arrayvalued', true);
m(pidx)=fsolve(@(z)[fun31(z)-10; fun3(z)-178.57145], [0.02; 0.04]);
fun44= @(z) integral(@(x) (100-p-x+min(x,max(0,fzero(@(y) (100-p-x+y).*(2.*z(2)+4.*z(1).*y).^2-1,1E-6)))).^(0.5).*spdf(x),0,50,'arrayvalued', true);
n(pidx)=feval(fun44,m(pidx));
z(pidx) = n(pidx) - integral(@(x) (100-x).^0.5.*spdf(x),0,50);
end
plot(pvals, z, 'd');
The error is:
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in FinalCaseCCPareto (line 61)
m(pidx)=fsolve(@(z)[fun31(z)-10; fun3(z)-178.57145], [0.02; 0.04]);
I think the error comes from the fact that, this line of code, m(pidx)=fsolve(@(z)[fun31(z)-10; fun3(z)-178.57145], [0.02; 0.04]) will return two numbers. I have tested that all the other parts are correct. Anyone can help me fix the code? Thank you in advance!

Accepted Answer

Matt J
Matt J on 6 Feb 2019
m(pidx,1:2)=fsolve(@(z)[fun31(z)-10; fun3(z)-178.57145], [0.02; 0.04]);
  3 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!