how can I integrate this function (1/(1+x.^2)) in matlab
Show older comments
I used many numerical integration methods like integral simpson trapoizal int but the graph is different and not like the one already I have so can I know please how to do this in matlab the function is 1/(1+x.^2) intervals of this integration contains variable called t takes values from [-15:15] now intervals from [ -t^1/2, Inf]
Answers (3)
Hi,
fun = @(x) 1./(1+x.^2)
sol = integral(fun,-15,15)
This gives you the numeric solution in the bounds [-15, 15].
An alternative solution (if you have access to symbolic toolbox) is:
syms x
fun = 1/(1+x^2)
sol_1 = int(fun)
sol_2 = int(fun,0,inf)
sol_3 = int(fun,-15,15)
Best regards
Stephan
11 Comments
suez canal university
on 5 Aug 2018
Edited: Walter Roberson
on 5 Aug 2018
Stephan
on 5 Aug 2018
Use x not u:
syms x
fun=1./(1+(x).^(2));
sol1=int(fun)
for t=-15:5:15
sol2=int(fun,t.^(-1/2),Inf)
end
Walter Roberson
on 5 Aug 2018
You are overwriting all of sol2 each iteration through the loop.
syms x fun(u)
fun(u) = 1./(1+(u).^(2));
sol1 = int(fun)
for tidx = 1 : 7
t = (tidx-4) * 5;
sol2(tidx) = int(fun, t.^(-1/2), Inf);
end
sol2
You will find that the first several entries come out 0. That is because you are trying to integrate over a complex range without having specified a path to follow. (At the moment I do not find a way to specify the path for a symbolic complex line integral; for numeric integrals with integrate() you specify it using the Waypoints option.)
suez canal university
on 5 Aug 2018
vpaintegral supports waypoints:
Unrtil now i also did not hear from this topic - im highly interested too
suez canal university
on 5 Aug 2018
Walter Roberson
on 5 Aug 2018
There is a closed form solution for t < 0, which is
-1i*atanh(1/sqrt(-t))
This will be complex valued. For t more negative than -1, this will be purely complex, with real part 0; for t greater than -1 to 0, this will have a mix of real and complex parts. At t = -1 itself, it is undefined, being -Inf*1i from the left and - Inf*1i - pi/2 from the right.
There are multiple ways of plotting complex values. Sometimes people plot two lines on the same 2D graph, one line representing the real part and the other line representing the imaginary part. Other times, people would instead switch to a 3D graph, with t on one axis, real() on a second axis, and imag() on a third axis.
Stephan
on 5 Aug 2018
@Walter did you get this solution by using matlab? How did you find it?
Walter Roberson
on 5 Aug 2018
I used Maple.
Walter Roberson
on 5 Aug 2018
vpaintegral() was added to the Symbolic Toolbox in R2016b.
suez canal university
on 5 Aug 2018
0 votes
suez canal university
on 5 Aug 2018
0 votes
1 Comment
Walter Roberson
on 5 Aug 2018
You cannot avoid that. You have t = -15 to +15 and you want to integrate over -t^(1/2) to infinity, but when t is negative, t^(1/2) is complex.
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!