[Math] Matlab integral with parameter

MATLAB

I'm a beginner with Matlab, and I'm trying to solve the following problem.

I'd like to define a function
$$F(x) = \int_0^{+\infty} \frac{\sin t}{1 + xt^4} \, dt$$
and plot it on the interval $[1,3]$.

I wrote the following code:

x = 1:0.01:3; 
y = []; 

for i = 1:201
    xi = 1 + (i-1)/100;
    y(i) = quadgk(@(t)sin(t)./(xi*t.^4 + 1), 0, inf); 
end 

plot(x,y)

This looks ridiculously complicated to me, and there's no obvious way to compute values of $F(x)$ after this.

I'd like to know how experienced Matlab users would program this.

Best Answer

I might do it this way:

integrand = @(x) (@(t) sin(t) ./ (1+x .*t .^4));

F = @(x) quadgk(integrand(x),0,Inf);

x = 1:0.01:3;
y = arrayfun(F,x);

plot(x,y)

enter image description here

Related Question