Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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;
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

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by