double integral using trapz
10 views (last 30 days)
I'm trying to approximate a double integral using traps. I'm not sure how to coding it.
-A given question
𝑓(𝑥, 𝑦) = (500*x*exp(y)) / (1 + 2*x^2)
Using Trapezoidal rule with △x, △y=0.5, 0.25, 0.125, 0.0625, 0.03125
-The code that I tired :
clc, clear all;
x = 0:0.5:4;
y = 0:0.5:4;
[X,Y] = meshgrid(x,y);
F = (500.*X.*exp(Y))/(1.+2.*X.^2);
I = trapz(y,trapz(x,F,2))
Parsa on 21 May 2022
In definition of F, you forgot a dot '.' , before '/ ' . Please try it and run your code again.
Also please take a look at the exapmle " Multiple Numerical Integrations " @doc:Trapezoidal numerical integration - MATLAB trapz (mathworks.com)