I have edited the code according to answers.
Can anyone explain the reason behind the errors and help me correcting the following code:
U = 1; e = @(q) 2*(1-cos(2*pi*q));hq = @(q,n0) ((e(q)).^2+2*U*n0*(e(q))).^0.5;y = @(q,n0) (((e(q))+(U*n0))/hq(q,n0))-1;a = -0.5;b = 0.5;v = @(n0) quad(@(q) y(q,n0),a,b);cv =@(n0) n0+(0.5*v(n0))-1;while U < 20n0 = 0.1;options = optimset('Display', 'iter'); n = fsolve(cv(n0),n0,0.1,options);plot(U,n)hold on U = U + 1;end
Errors:
Error using quad (line 75) The integrand function must return an output vector of the same length as the input vector.Error in @(n0)quad(@(q)y(q,n0),a,b)Error in @(n0)n0+(0.5*v(n0))-1Error in simulv1 (line 12)n = fsolve(cv(n0),n0,0.1,options);
Best Answer