Getting errors specifying an anonymous function, integrating and getting points from it.

1 view (last 30 days)
jayash on 22 Feb 2015
Answered: Star Strider on 23 Feb 2015
I want solve the follwing equation and get the values of n0 for different values of U ie. U=1:1:20;
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;
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

Accepted Answer

Star Strider
Star Strider on 23 Feb 2015
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;
v = quad(@(q) y(q,n0,U), a, b);
Note: Untested code.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by