hi I've search and read but I couldn't solve this one in matlab. please help me out to solve this problem integral_0^1 x^n e^(x-1) dx
Generally, you can use different approaches to calculate the required integral:
1) Symbolic Toolbox --> I'd go for this one because of considerations on n
syms x n;
f = x.^n.*exp( x - 1 );
int(f,0,1)
2) quad
, integral
functions
g = @(n) (integral(@(x) x.^n.*exp(x-1),0,1));
g = @(n) (quad(@(x) x.^n.*exp(x-1),0,1));
Then you can evaluate the result depending on n
.
3) trapz
function
x = 0:.001:1;
y = x.^n.*exp( x - 1 );
trapz(x,y)
But, in this specific case, the calculation of the integral is driven by the exponent n
.
Since I suppose and assume that you know how the integral of 'x.^n' behaves for different n
, I will skip the discussion.