how can i solve the matlab warning message
1 view (last 30 days)
Show older comments
shayma mohammed
on 20 Aug 2014
Commented: shayma mohammed
on 21 Aug 2014
hello i'm a PHD student and a new in the matlab i have a formula that i need to integrate it numerically and plot it when i tried to do this result contain the letter i and the warning message appeard
Q = quad(@myfun,0,0.693)
Q =
-0.0000 + 0.0037i
This warning message appeared Warning: Imaginary parts of complex X and/or Y arguments ignored
i don't know what should i do please help me, i will send the file.m in the attachement file
4 Comments
Image Analyst
on 20 Aug 2014
Do you want to suppress the warning, so that it does not appear, or do you want to avoid the situation that gave rise to the warning?
Accepted Answer
Roger Stafford
on 20 Aug 2014
The range of integration you are using, 0 to 0.693, includes values which lie inside the interval, -m < x < +m, and that will give you negative values inside the square root in sqrt(x^2-m^2). The square root of a negative number does not give a real result, but is known in mathematics as an "imaginary" number. That is what the 'i' in your result indicates. Combinations of real and imaginary numbers are known as "complex" numbers. You have a complex result.
By the way, in your integrand two of the square root expressions, cancel each other out, but there is a third one left inside the exponential which is what is causing you the complex result.
3 Comments
dpb
on 20 Aug 2014
According to the help...
>> help quad
quad Numerically evaluate integral, adaptive Simpson quadrature.
Q = quad(FUN,A,B) tries to approximate the integral of scalar-valued
function FUN from A to B to within an error of 1.e-6 using recursive
adaptive Simpson quadrature. FUN is a function handle. The function
Y=FUN(X) should accept a vector argument X and return a vector result
Y, the integrand evaluated at each element of X.
So, basically, "yes" with the (I'd hope obvious) caveat that "any formula" will be whatever is coded in the function referenced by the passed function handle of the first argument.
More Answers (0)
See Also
Categories
Find more on Parallel Computing Fundamentals 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!