Evaluate double integral using trapezoidal rule

4 ビュー (過去 30 日間)
Mark Johnson
Mark Johnson 2015 年 4 月 15 日
コメント済み: Sean de Wolski 2015 年 4 月 15 日
I have an assignment to evaluate a double integral using trapezoidal rule. The first part was to evaluate a double integral using trapezoidal rule with limits 0 <= x <= 2, 0 <= y <= 1
I have a working script for that:
N = 100;
xh= 1.25;
x = linspace(0,2,N);
y = linspace(0,1,0.5*N);
dx = diff(x(1:2));
dy = diff(y(1:2));
[x,y] = meshgrid(x,y);
funk = exp(-10.*((x-xh).^2+y.^2)).*cos(y.*(x-xh));
funk(2:end-1,:) = funk(2:end-1,:)*2;
funk(:,2:end-1) = funk(:,2:end-1)*2;
out = sum(funk(:))*dx*dy/4;
disp(out)
Now for the second part the limits are 0 <= x <= 2, 0 <= y <= ((pi*x)/2)
How do I get y (line 4 in code) to take corresponding x values from the x-matrix to create the y-matrix? If I get that to work I shouldn't have to change anything else in the code right, or am I missing something?

回答 (1 件)

Sean de Wolski
Sean de Wolski 2015 年 4 月 15 日
編集済み: Sean de Wolski 2015 年 4 月 15 日
How about instead of re-linspacing:
y = pi*x/2
  2 件のコメント
Mark Johnson
Mark Johnson 2015 年 4 月 15 日
How do you mean? Maybe I'm misinterpreting you but won't that give me just one value for y. From my understanding I need a matrix, the same size as x, for y.
Sean de Wolski
Sean de Wolski 2015 年 4 月 15 日
x is a vector (output from linspace) so x multiplied my scalars will also be a vector.
Run it!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by