How to fix errors within double integral.

조회 수: 7 (최근 30일)
Amanda
Amanda 2022년 10월 30일
답변: Carlos Guerrero García 2022년 11월 26일
I need to graph the region. This is the code I started with
fun = @(x,y) 5
xmin = -3
xmax= 3
ymin = @(x) -1.*sqrt(9- x.^2)
ymax = @(x) sqrt(9- x.^2);
q = integral2(fun,xmin,xmax,ymin,ymax)
Whenever I try to run this I get several error meassages.
Error using integral2Calc>integral2t/tensor (line 241)
Integrand output size does not match the input size.
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] =
integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 105)
Q =
integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in math241_project2 (line 7)
q = integral2(fun,xmin,xmax,ymin,ymax)

채택된 답변

Paul
Paul 2022년 10월 30일
편집: Paul 2022년 10월 30일
Hi @Amanda,
The doc page for integral2 say that the function that defines the integrand "must accept two arrays of the same size and return an array of corresponding values." However, fun in the Question always returns a scalar for any pair of inputs. Correct fun as shown below so it returns an array the same size as x with all elements equal to 5
fun = @(x,y) 5*ones(size(x));
xmin = -3;
xmax = 3;
ymin = @(x) -1.*sqrt(9 - x.^2);
ymax = @(x) sqrt(9 - x.^2);
q = integral2(fun,xmin,xmax,ymin,ymax)
q = 141.3717
  댓글 수: 5
Torsten
Torsten 2022년 10월 30일
r = 3;
5 * pi*r^2
ans = 141.3717
Can you now imagine what the domain of integration is ?
Paul
Paul 2022년 10월 30일
Suppose I have a function defined like this
y = @(x) x.^2;
And I want to plot it between
xmin = -5;
xmax = 5;
Then I can make a plot like this
x = xmin:0.01:xmax;
plot(x,y(x))
If I want to make the apsect ratio 1:1
axis equal
Check hold to learn one way to add an additional line to the plot.

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

추가 답변 (1개)

Carlos Guerrero García
Carlos Guerrero García 2022년 11월 26일
For plotting the region, I suggest the following code:
x=-3:0.05:3; % Setting up the range of X
y=sqrt(9-x.^2); % Calculating the Y values
fill([x flip(x)],[y -flip(y)],'b','FaceAlpha',0.5); % [x,flip(x)] for forwards/towards advance in X and mapping [y -flip(y)]
% In the preceding line 'b' is for a blue drawing, and setting 'FaceAlpha' to 1/2 for trasparency
grid on; % plotting the grid
axis equal; axis([-3 3 -3 3]) % Setting up a nice view
And the following code determines the value of the integral in the statement:
syms x;
int(int(5,-sqrt(9-x^2),sqrt(9-x^2)),-3,3)
ans = 

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by