Getting errors specifying an anonymous function, integrating and getting points from it.
1 次查看(过去 30 天)
显示 更早的评论
I want solve the follwing equation and get the values of n0 for different values of U ie. U=1:1:20;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/147250/image.jpeg)
the above equation has singularity at q=0, therefore I used 'quad' instead of 'integral'. Please let me know if this is correct or not?
function cv = test2(n0,U)
eq = @(q,n0,U) 2*(1 - cos(2*pi*q));
hq = @(q,n0,U) ((eq)^2 + 2*U*n0*(eq))^(1/2);
y = @(q,n0,U) (((eq) + (U*n0))/hq) - 1;
a = -0.5;
b = 0.5;
v = @(q) quad(y,a,b);
cv = n0+(0.5*v)-1;
end
but I get the following errors
Undefined function 'mtimes' for input arguments of type 'function_handle'.
Error in test2 (line 8)
cv = n0+(0.5*v)-1;
Anybody please help me out. Thanks
0 个评论
采纳的回答
Star Strider
2015-2-23
You need to use the argument lists in functions you reference within another function. I can’t run your code, so try this:
hq = @(q,n0,U) ((eq(q,n0,U)).^2 + 2*U.*n0.*(eq(q,n0,U))).^(1/2);
y = @(q,n0,U) (((eq(q,n0,U)) + (U*n0))./hq(q,n0,U)) - 1;
and:
v = quad(@(q) y(q,n0,U), a, b);
Note: Untested code.
0 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!