# Error calculating an integral: ""Input function must return 'double' or 'single' values. Found 'sym'."" How can i get the %% integral(F_potext,0,a) %% done? Thanks for the help :)

조회 수: 8(최근 30일)
Enrique Villa Coronado 2020년 12월 15일
댓글: Enrique Villa Coronado 2020년 12월 18일
a=3; b=(2/3)*a; h=0.01;
q0 = -1000;
syms x y z c
X_m = [0 0 (x/a)^2 (x/a)^3 (x/a)^4];
Y_n = [0 0 (y/b)^2 (y/b)^3 (y/b)^4];
fn = sym([0 0 0 0 0]);
for i=1:5
for j=1:5
fn(i) = fn(i) + X_m(i)*Y_n(j);
end
end
Pot_ext = [0 0 0 0 0];
for i=1:5
F_potext = @(x) ((q0.*x)./a)*subs(fn(i),y,2*b/3);
Pot_ext(i) = integral(F_potext,0,a)
end

댓글을 달려면 로그인하십시오.

### 채택된 답변

Walter Roberson 2020년 12월 18일
a=3; b=(2/3)*a; h=0.01;
q0 = -1000;
syms x y z c
X_m = [0 0 (x/a)^2 (x/a)^3 (x/a)^4];
Y_n = [0 0 (y/b)^2 (y/b)^3 (y/b)^4];
fn = sym([0 0 0 0 0]);
for i=1:5
for j=1:5
fn(i) = fn(i) + X_m(i)*Y_n(j);
end
end
Pot_ext = [0 0 0 0 0];
for i=1:5
F_potext = matlabFunction(((q0.*x)./a)*subs(fn(i),y,2*b/3), 'vars', x);
Pot_ext(i) = integral(F_potext,0,a, 'arrayvalued', true);
end
Pot_ext
Pot_ext = 1×5
0 0 -703.7037 -562.9630 -469.1358
The reason for the 'arrayvalued', true is that the first two entries in fn come out as 0, so the code does a
matlabFunction(sym(0), 'vars', x)
which generates @(x) 0.0 as the anonymous code. But when you use that code in integral() or fplot() you have a problem because those pass in arrays of x values and require that you return back an array of the same size, but @(x) 0.0 returns back a single x not an array.
##### 댓글 수: 1표시 없음숨기기 없음
Enrique Villa Coronado 2020년 12월 18일
Got it, thanks so much!!! Really appreciate it

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

Abhishek Gupta 2020년 12월 18일
Hi,
Referring to the following MATLAB Answers, which might help you in resolving the issue: -

댓글을 달려면 로그인하십시오.

### 범주

Find more on Data Type Identification in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by