fsolve, In an assignment A(:) = B, the number of elements in A and B must be the same.
20 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Discontinuities in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!