필터 지우기
필터 지우기

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;
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

채택된 답변

Star Strider
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개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by